summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp
index 6565874a340..c745366cf44 100644
--- a/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp
+++ b/clang-tools-extra/clang-tidy/misc/BoolPointerImplicitConversion.cpp
@@ -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
OpenPOWER on IntegriCloud