[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.

llvm-svn: 215439
This commit is contained in:
Benjamin Kramer 2014-08-12 12:12:57 +00:00
parent 6318f7614f
commit 242b5b808b
2 changed files with 12 additions and 5 deletions

View File

@ -24,6 +24,9 @@ AST_MATCHER(QualType, isBoolean) { return Node->isBooleanType(); }
namespace tidy {
void BoolPointerImplicitConversion::registerMatchers(MatchFinder *Finder) {
auto InTemplateInstantiation = hasAncestor(
decl(anyOf(recordDecl(ast_matchers::isTemplateInstantiation()),
functionDecl(ast_matchers::isTemplateInstantiation()))));
// Look for ifs that have an implicit bool* to bool conversion in the
// condition. Filter negations.
Finder->addMatcher(
@ -32,7 +35,8 @@ void BoolPointerImplicitConversion::registerMatchers(MatchFinder *Finder) {
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(const MatchFinder::MatchResult &Result) {
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

View File

@ -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)
}