[PATCH] D96139: [clang-tidy] Simplify inaccurate erase check

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 13 05:52:36 PST 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf2f920b987f3: [clang-tidy] Simplify inaccurate erase check (authored by stephenkelly).

Changed prior to commit:
  https://reviews.llvm.org/D96139?vs=321747&id=323550#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96139/new/

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,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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96139.323550.patch
Type: text/x-patch
Size: 2802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210213/bc3cc7a9/attachment-0001.bin>


More information about the cfe-commits mailing list