Skip to content

fix: emit warning for unknown preprocessor directives - #219

Open
liuxiaopai-ai wants to merge 1 commit into
anthropics:mainfrom
liuxiaopai-ai:fix/warn-unknown-preprocessor-directives
Open

fix: emit warning for unknown preprocessor directives#219
liuxiaopai-ai wants to merge 1 commit into
anthropics:mainfrom
liuxiaopai-ai:fix/warn-unknown-preprocessor-directives

Conversation

@liuxiaopai-ai

Copy link
Copy Markdown

Summary

Emit a warning diagnostic when the preprocessor encounters an unknown directive (e.g. #defin, #inclde). Previously these were silently ignored, which made typos in preprocessor directives very hard to catch.

Fixes #172

Changes

  • src/frontend/preprocessor/pipeline.rs: In the process_directive() catch-all arm, instead of silently ignoring unknown directives, push a PreprocessorDiagnostic warning with the message unknown preprocessing directive #<keyword>.
  • Added 6 unit tests covering:
    • Unknown directive (#defin) emits a warning
    • Another typo (#inclde) emits a warning
    • Known directives (#define, #undef, #ifdef, #endif) produce no warnings
    • Null directive (# alone) produces no warning (valid per C standard)
    • Unknown directives inside inactive conditional blocks (#if 0) do not warn
    • Correct source location (file, line) is reported in the diagnostic

Behavior

This matches GCC and Clang behavior, which both emit a warning (or error) for unknown preprocessing directives:

test.c:1:2: warning: unknown preprocessing directive #defin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P3] Unknown preprocessor directives silently ignored — no warning for typos like #defin

1 participant