llvm / llvm/llvm-project

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

Open
#160,152 1 comment 0 reactions 0 assignees View on GitHub
clang:diagnostics confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Background

This issue is filed based on a suggestion by @Endilll during a code [review](https://github.com/llvm/llvm-project/pull/155570#discussion_r2368814335).

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:
```c
#if 1, 2
#endif
```

Clang currently produces a diagnostic like this:
```c
:1:6: error: expected end of line in preprocessor expression
1 | #if 1, 2
| ^
: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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.