[clang-tools-extra] r215439 - [clang-tidy] Disable the warning on implicit bool* to bool conversion in macros.

Alexander Kornienko alexfh at google.com
Tue Aug 12 07:52:28 PDT 2014


On Tue, Aug 12, 2014 at 2:12 PM, Benjamin Kramer <benny.kra at googlemail.com>
wrote:

> Author: d0k
> Date: Tue Aug 12 07:12:57 2014
> New Revision: 215439
>
> URL: http://llvm.org/viewvc/llvm-project?rev=215439&view=rev
> Log:
> [clang-tidy] Disable the warning on implicit bool* to bool conversion in
> macros.
>
> It's just too noisy and the warning isn't very helpful in those cases.
>
> Modified:
>
> clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp
>
> clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp
>
> Modified:
> clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp?rev=215439&r1=215438&r2=215439&view=diff
>
> ==============================================================================
> ---
> clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp
> (original)
> +++
> clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp
> Tue Aug 12 07:12:57 2014
> @@ -24,6 +24,9 @@ AST_MATCHER(QualType, isBoolean) { retur
>  namespace tidy {
>
>  void BoolPointerImplicitConversion::registerMatchers(MatchFinder *Finder)
> {
> +  auto InTemplateInstantiation = hasAncestor(
> +      decl(anyOf(recordDecl(ast_matchers::isTemplateInstantiation()),
> +                 functionDecl(ast_matchers::isTemplateInstantiation()))));
>

Can you pull isInTemplateInstantiation out to ASTMatchers.h? Manuel seems
to think it is the right way to handle this for now.


>    // Look for ifs that have an implicit bool* to bool conversion in the
>    // condition. Filter negations.
>    Finder->addMatcher(
> @@ -32,7 +35,8 @@ void BoolPointerImplicitConversion::regi
>                         hasSourceExpression(expr(
>                             hasType(pointerType(pointee(isBoolean()))),
>
> ignoringParenImpCasts(declRefExpr().bind("expr")))),
> -                       isPointerToBoolean()))))).bind("if"),
> +                       isPointerToBoolean())))),
> +             unless(InTemplateInstantiation)).bind("if"),
>        this);
>  }
>
> @@ -41,6 +45,10 @@ BoolPointerImplicitConversion::check(con
>    auto *If = Result.Nodes.getStmtAs<IfStmt>("if");
>    auto *Var = Result.Nodes.getStmtAs<DeclRefExpr>("expr");
>
> +  // Ignore macros.
> +  if (Var->getLocStart().isMacroID())
> +    return;
> +
>    // Only allow variable accesses for now, no function calls or member
> exprs.
>    // Check that we don't dereference the variable anywhere within the if.
> This
>    // avoids false positives for checks of the pointer for nullptr before
> it is
>
> Modified:
> clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp?rev=215439&r1=215438&r2=215439&view=diff
>
> ==============================================================================
> ---
> clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp
> (original)
> +++
> clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp
> Tue Aug 12 07:12:57 2014
> @@ -33,10 +33,6 @@ void foo() {
>  #define TESTMACRO if (b || F())
>
>    TESTMACRO {
> -// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dubious check of 'bool *'
> against 'nullptr'
> -// Can't fix this.
> -// CHECK-FIXES: #define TESTMACRO if (b || F())
> -// CHECK-FIXES: TESTMACRO {
>    }
>
>    t(b);
> @@ -81,4 +77,7 @@ void foo() {
>
>    if (d.b)
>      (void)*d.b; // no-warning
> +
> +#define CHECK(b) if (b) {}
> +  CHECK(c)
>  }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140812/01aa5ac5/attachment.html>


More information about the cfe-commits mailing list