<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97482>97482</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Diagnostic for pp directives in the body of a function-like macro could be improved
</td>
</tr>
<tr>
<th>Labels</th>
<td>
enhancement,
clang:diagnostics
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Sirraide
</td>
</tr>
</table>
<pre>
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).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVEuP2zYQ_jX0ZbCGTPmlgw6ONwvkVqA99DoiR-JkKVLgw67_fUFJ8QbNooghPyh6Zr6XiDHy4IhacfgiDq8bzMn40P7JISBr2nReP9q_DEHvrfV3dgMor0nIK9wNKwMcwXc39jnaB7C1L70PI2lRvYrqIo7Vcikhv5RruStrTT07gr-FPAvZwO-9xOH6bMBO2awJRH2NSbPfGlF__c_QZRkoZpsisINkOAKF4MOn_yy9fA6KSqv6Itf3WlFfQMiTkLWQp8La-bSKQhq6ByCMqIKHCQOOlGidUYBLEKcr_D_qleLpWnh-zmQRfMR3ihDJRSqcEG6och6LI11OoNBBR4DQcQLlXZ9jMY0dKIwU4W4oECRDUPoeruJYFTbRQ48BfN9D8vN24MEkSAYTPHwG7Z34KsW5Ek2TIBIBJ8AECINFp-ZEoNPwPcd5uwz90HtRnw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