diff --git a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h --- a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h +++ b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.h @@ -29,6 +29,9 @@ } void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + llvm::Optional getCheckTraversalKind() const override { + return TK_IgnoreUnlessSpelledInSource; + } }; } // namespace performance diff --git a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp --- a/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientAlgorithmCheck.cpp @@ -35,27 +35,24 @@ "::std::unordered_set", "::std::unordered_map", "::std::unordered_multiset", "::std::unordered_multimap")); - const auto Matcher = traverse( - TK_AsIs, + const auto Matcher = callExpr( callee(functionDecl(Algorithms)), hasArgument( - 0, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr( + 0, cxxMemberCallExpr( callee(cxxMethodDecl(hasName("begin"))), on(declRefExpr( hasDeclaration(decl().bind("IneffContObj")), anyOf(hasType(ContainerMatcher.bind("IneffCont")), hasType(pointsTo( ContainerMatcher.bind("IneffContPtr"))))) - .bind("IneffContExpr"))))))), + .bind("IneffContExpr")))), hasArgument( - 1, cxxConstructExpr(has(ignoringParenImpCasts(cxxMemberCallExpr( - callee(cxxMethodDecl(hasName("end"))), - on(declRefExpr( - hasDeclaration(equalsBoundNode("IneffContObj"))))))))), - hasArgument(2, expr().bind("AlgParam")), - unless(isInTemplateInstantiation())) - .bind("IneffAlg")); + 1, cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"))), + on(declRefExpr(hasDeclaration( + equalsBoundNode("IneffContObj")))))), + hasArgument(2, expr().bind("AlgParam"))) + .bind("IneffAlg"); Finder->addMatcher(Matcher, this); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-algorithm.cpp @@ -1,5 +1,4 @@ -// RUN: %check_clang_tidy -std=c++11,c++14 %s performance-inefficient-algorithm %t -// FIXME: Fix the checker to work in C++17 mode. +// RUN: %check_clang_tidy %s performance-inefficient-algorithm %t namespace std { template struct less {