Issue 89921
Summary clang-tidy wrongly reports bugprone-macro-parentheses on non-arguments
Labels clang-tidy
Assignees
Reporter j-jorge
    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 :)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to