Skip to content

[clang][Preprocessor] Improve diagnostic message for top-level comma in #if expressions #160152

@swote-git

Description

@swote-git

Background

This issue is filed based on a suggestion by @Endilll during a code review.

The current diagnostic for a top-level comma in a preprocessor expression is not very actionable, as it points to the end of the line instead of the problematic token.


Current Behavior

Given the following code:

#if 1, 2
#endif

Clang currently produces a diagnostic like this:

<stdin>:1:6: error: expected end of line in preprocessor expression
    1 | #if 1, 2
      |      ^
<stdin>:1:2: error: unterminated conditional directive
    1 | #if 1, 2
      |  ^

A better diagnostic would be more directly that commas should not be included. Rather than just indicating EOL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions