[cfe-dev] clang-tidy misc-macro-parentheses

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Thu Dec 22 06:50:01 PST 2016


On Thu, Dec 22, 2016 at 7:43 AM, Alfred Zien via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Hi!
>
> clang-tidy misc-macro-parentheses checks macros that supplied with
> command-line arguments.
>
> Lets say I have simple foo.c:
> int main() {};
>
> And I write to console:
>
> clang-tidy foo.c -checks=misc-macro-parentheses -- -DVERSION=1.23-5
>
> It prints out
>
> warning: macro replacement list should be enclosed in parentheses
> [misc-macro-parentheses]
>
> Firstly, it is very hard to find out why it occurs. Secondly, I couldn't
> figure out how to suppress it. Anybody knows good way to do it? Apart from
> this. this seems to be a very good check.

I can see how that would be difficult to discover why the diagnostic
is triggering; there's no source location for the macro. Perhaps there
is a way to improve the diagnostic in that case.

The diagnostic is triggered because you are using a subtraction
expression as the macro definition, so if you were to use this in an
integer expression, you may get the wrong results. If your version
isn't meant to be treated as an integral value, perhaps you could make
it into a string literal instead? That would silence the diagnostic
without requiring parens.

~Aaron

>
> I'm using compile_commands.json in my project, so I can't control compiler
> arguments directly.
>
> Thanks for any help!
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list