forked from OSchip/llvm-project
[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:
parent
6318f7614f
commit
242b5b808b
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue