<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/89921>89921</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-tidy wrongly reports bugprone-macro-parentheses on non-arguments
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
j-jorge
</td>
</tr>
</table>
<pre>
Given the following codeĀ :
```c++
#include <cstdio>
#ifndef FOO
#define FOO a-b
#endif
int main()
{
#define STR0(x) #x
#define STR(x) STR0(x)
printf("%s\n", STR(FOO));
}
```
A run of `clang-tidy --checks=bugprone-macro-parentheses` will complain about the need of replacing `a` and `b` by `(a)` and `(b)` ([Compiler Explorer demo](https://godbolt.org/z/ETdvP75av)) :
```
warning: macro replacement list should be enclosed in parentheses [bugprone-macro-parentheses]
[<source>:4:14: warning: macro replacement list should be enclosed in parentheses [bugprone-macro-parentheses]](javascript:;)
4 | #define FOO a-b
```
I believe this is a false positive. Since none of `a` or `b` are arguments of the macro they should not be considered by the check.
My actual use case is similar to this code. I have a preprocessor definition coming from the command line (`-DFOO=some-string-with-dashes`) which I turn into a C-string in the code via the `STR()` macro. The workaround is to drop the `STR` macro and put the quotes in the command-line, but I would have preferred no workaround :)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VcuSqzYQ_Rp504ULS2DDgoUf49QsUjeVOz8gUAOaKyQiCXucr081eGacSW6WqVJhPVrq7tPntGUIurOIFcsPLD-t5BR756vX5NX5Dle1U7fqF31BC7FHaJ0x7qptB41TyI6c7VMm9iw9sXTPtukyGsYPNJZdLrRtzKQQmDg2ISrtmHi6H36YtFZhC-dv3z62FLbaIm2BTOqPbbRKt4-3tY0wSG0ZLxgv7ye7w9d3vr_8njJevDFeAuPi7V_O348fTBcrgNFrG9vZBWc8Dyw_2nl6vF-kyHlJQ7y73p2-4LIs9-AnC64FQsp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