[PATCH] Add readability-simplify-boolean-expr check to clang-tidy

Ismail Pazarbasi ismail.pazarbasi at gmail.com
Mon Feb 16 03:30:01 PST 2015


On Mon, Feb 16, 2015 at 3:09 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Sun, Feb 15, 2015 at 6:04 PM, Richard <legalize at xmission.com> wrote:
>>
>> Thinking about this a little more, I'm conflicted as to whether or not it
>> should allow the simplification if the boolean constant came from a macro.
>> If the macro is a feature detection macro, then I'm enabling/disabling
>> chunks of code at runtime based on the resolution of the feature detection
>> and I shouldn't be so quick to simplify that to always true or always false.
>
>
> I believe that was Ismael's point, if it wasn't at least it's mine. It's
> unfortunate to whitelist all macros like that, but I think it'll be
> necessary to get the false positive % down. Check out similar changes Ted
> Kremenek made to Clang's -Wunreachable-code warning to reduce the false
> positives about a year ago. You'll find that if (MACRO) { ... } else { ... }
> doesn't produce an unreachable code warning on either path.
>
Yes, that was my concern. I think we should avoid correcting or
warning about macros eagerly. There is too much macro-generated code
in libraries, and we can't do much about them. Macros written in main
source file can be analyzed, however. It seems like we have a matcher
for macro expansions in main file: `isExpansionInMainFile`; is this
usable?

  // foo.h
  #define EXPECT_FALSE(x) ((x) == false) // macro written in a header file

  // foo.cpp
  #include "foo.h"
  #define MY_EXPECT_FALSE(x) ((x) == false)
  static void f() {
    if (EXPECT_FALSE(0 == 1)); // ok
    if (MY_EXPECT_FALSE(0 == 1)); // warn
  }

>>
>>
>>
>> http://reviews.llvm.org/D7648
>>
>> EMAIL PREFERENCES
>>   http://reviews.llvm.org/settings/panel/emailpreferences/
>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list