diff --git a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h @@ -31,6 +31,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 bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp @@ -22,25 +22,18 @@ callExpr( callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))), hasArgument( - 1, - anyOf(cxxConstructExpr(has(ignoringImplicit( - cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end")))) - .bind("end")))), - anything()))) + 1, optionally(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end")))) + .bind("end")))) .bind("alg"); const auto DeclInStd = type(hasUnqualifiedDesugaredType( tagType(hasDeclaration(decl(isInStdNamespace()))))); Finder->addMatcher( - traverse( - TK_AsIs, - cxxMemberCallExpr( - on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd)))), - callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1), - hasArgument(0, has(ignoringImplicit(anyOf( - EndCall, has(ignoringImplicit(EndCall)))))), - unless(isInTemplateInstantiation())) - .bind("erase")), + cxxMemberCallExpr( + on(anyOf(hasType(DeclInStd), hasType(pointsTo(DeclInStd)))), + callee(cxxMethodDecl(hasName("erase"))), argumentCountIs(1), + hasArgument(0, EndCall)) + .bind("erase"), this); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp @@ -1,5 +1,4 @@ -// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-inaccurate-erase %t -// FIXME: Fix the checker to work in C++17 mode. +// RUN: %check_clang_tidy %s bugprone-inaccurate-erase %t namespace std { template struct vec_iterator {