<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 12, 2014 at 2:12 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Tue Aug 12 07:12:57 2014<br>
New Revision: 215439<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=215439&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=215439&view=rev</a><br>
Log:<br>
[clang-tidy] Disable the warning on implicit bool* to bool conversion in macros.<br>
<br>
It's just too noisy and the warning isn't very helpful in those cases.<br>
<br>
Modified:<br>
clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp<br>
clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp?rev=215439&r1=215438&r2=215439&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp?rev=215439&r1=215438&r2=215439&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-tidy/misc/BoolPointerImplicitConversion.cpp Tue Aug 12 07:12:57 2014<br>
@@ -24,6 +24,9 @@ AST_MATCHER(QualType, isBoolean) { retur<br>
namespace tidy {<br>
<br>
void BoolPointerImplicitConversion::registerMatchers(MatchFinder *Finder) {<br>
+ auto InTemplateInstantiation = hasAncestor(<br>
+ decl(anyOf(recordDecl(ast_matchers::isTemplateInstantiation()),<br>
+ functionDecl(ast_matchers::isTemplateInstantiation()))));<br></blockquote><div><br></div><div>Can you pull isInTemplateInstantiation out to ASTMatchers.h? Manuel seems to think it is the right way to handle this for now.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// Look for ifs that have an implicit bool* to bool conversion in the<br>
// condition. Filter negations.<br>
Finder->addMatcher(<br>
@@ -32,7 +35,8 @@ void BoolPointerImplicitConversion::regi<br>
hasSourceExpression(expr(<br>
hasType(pointerType(pointee(isBoolean()))),<br>
ignoringParenImpCasts(declRefExpr().bind("expr")))),<br>
- isPointerToBoolean()))))).bind("if"),<br>
+ isPointerToBoolean())))),<br>
+ unless(InTemplateInstantiation)).bind("if"),<br>
this);<br>
}<br>
<br>
@@ -41,6 +45,10 @@ BoolPointerImplicitConversion::check(con<br>
auto *If = Result.Nodes.getStmtAs<IfStmt>("if");<br>
auto *Var = Result.Nodes.getStmtAs<DeclRefExpr>("expr");<br>
<br>
+ // Ignore macros.<br>
+ if (Var->getLocStart().isMacroID())<br>
+ return;<br>
+<br>
// Only allow variable accesses for now, no function calls or member exprs.<br>
// Check that we don't dereference the variable anywhere within the if. This<br>
// avoids false positives for checks of the pointer for nullptr before it is<br>
<br>
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp<br>
URL: <a href="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" target="_blank">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</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp (original)<br>
+++ clang-tools-extra/trunk/test/clang-tidy/misc-bool-pointer-implicit-conversion.cpp Tue Aug 12 07:12:57 2014<br>
@@ -33,10 +33,6 @@ void foo() {<br>
#define TESTMACRO if (b || F())<br>
<br>
TESTMACRO {<br>
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: dubious check of 'bool *' against 'nullptr'<br>
-// Can't fix this.<br>
-// CHECK-FIXES: #define TESTMACRO if (b || F())<br>
-// CHECK-FIXES: TESTMACRO {<br>
}<br>
<br>
t(b);<br>
@@ -81,4 +77,7 @@ void foo() {<br>
<br>
if (d.b)<br>
(void)*d.b; // no-warning<br>
+<br>
+#define CHECK(b) if (b) {}<br>
+ CHECK(c)<br>
}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br><br>
</div></div>