Issue 97482
Summary [Clang] Diagnostic for pp directives in the body of a function-like macro could be improved
Labels enhancement, clang:diagnostics
Assignees
Reporter Sirraide
    The following code, which is obviously ill-formed
```c++
#define X()                                       \
#include <stdio.h>
```
results in this error
```
<source>:2:2: error: '#' is not followed by a macro parameter
    2 | #include <stdio.h>
      |  ^
```
which makes sense in a vacuum, but can be a bit confusing in cases where the `\` is so far off to the right that you don’t see it at a glance, and just seeing this error in the console is rather unhelpful...

A fix for this that I thought of is, if the token after `#` is not a macro parameter, but rather an identifier that matches a known preprocessor directive (i.e. `include`, `define`, `pragma`, ...), then we could either change the error or add a note that says something along the lines of ‘Preprocessor directives may not appear in the body of a macro’ (which I know isn’t what this is according to the grammar, but it’s what the user intended).

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to