[cfe-dev] clang-tidy misc-macro-parentheses
Aaron Ballman via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 22 08:03:19 PST 2016
On Thu, Dec 22, 2016 at 10:35 AM, Alfred Zien <zienag at yandex-team.ru> wrote:
> I can totally understand why such definition is bad. Unfortunately, I can't
> change it, because it is part of very big project (chromium,
> https://chromium.googlesource.com/chromium/src/build/config/+/master/compiler/BUILD.gn,
> search for CR_CLANG_REVISION, it is result of script execution, in my case,
> it is 282487-1, and I get -DCR_CLANG_REVISION=282487-1), that propagates it
> in every file, that is building with their config.
>
> So, I can only try to suppress it, or abandon that check completely.
That's unfortunate! I think the check is working as intended, so I
don't think there's anything to be done with the check beyond trying
to make the diagnostic more obvious when the macro is defined on the
command line.
~Aaron
>
> On 22 Dec 2016, at 17:50, Aaron Ballman <aaron at aaronballman.com> wrote:
>
> 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