[PATCH] D96139: [clang-tidy] Simplify inaccurate erase check
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 5 06:44:58 PST 2021
steveire created this revision.
steveire added reviewers: aaron.ballman, njames93.
Herald added subscribers: nullptr.cpp, xazax.hun.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
The normalization of matchers means that this now works in all language
modes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96139
Files:
clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-inaccurate-erase.cpp
+++ 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 <typename T> struct vec_iterator {
Index: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.h
+++ 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<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
@@ -22,25 +22,19 @@
callExpr(
callee(functionDecl(hasAnyName("remove", "remove_if", "unique"))),
hasArgument(
- 1,
- anyOf(cxxConstructExpr(has(ignoringImplicit(
- cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"))))
- .bind("end")))),
- anything())))
+ 1, anyOf(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"))))
+ .bind("end"),
+ anything())))
.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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96139.321747.patch
Type: text/x-patch
Size: 2833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210205/a7cb6fba/attachment.bin>
More information about the cfe-commits
mailing list