[clang-tools-extra] r230483 - [clang-tidy] Fixed a false positive case in misc-inaccurate-erase checker.

Gabor Horvath xazax.hun at gmail.com
Wed Feb 25 04:17:03 PST 2015


Author: xazax
Date: Wed Feb 25 06:17:03 2015
New Revision: 230483

URL: http://llvm.org/viewvc/llvm-project?rev=230483&view=rev
Log:
[clang-tidy] Fixed a false positive case in misc-inaccurate-erase checker.

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp?rev=230483&r1=230482&r2=230483&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp Wed Feb 25 06:17:03 2015
@@ -26,10 +26,10 @@ void InaccurateEraseCheck::registerMatch
 
   Finder->addMatcher(
       memberCallExpr(
-          on(hasType(namedDecl(matchesName("std::")))),
+          on(hasType(namedDecl(matchesName("^::std::")))),
           callee(methodDecl(hasName("erase"))), argumentCountIs(1),
           hasArgument(0, has(callExpr(callee(functionDecl(matchesName(
-                                          "std::(remove_if|remove|unique)"))),
+                                          "^::std::(remove(_if)?|unique)$"))),
                                       CheckForEndCall).bind("InaccAlgCall"))),
           unless(isInTemplateInstantiation())).bind("InaccErase"),
       this);

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp?rev=230483&r1=230482&r2=230483&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-inaccurate-erase.cpp Wed Feb 25 06:17:03 2015
@@ -2,10 +2,13 @@
 // REQUIRES: shell
 
 namespace std {
-struct vec_iterator {};
+template <typename T> struct vec_iterator {
+  T *ptr;
+  vec_iterator operator++(int);
+};
 
 template <typename T> struct vector {
-  typedef vec_iterator iterator;
+  typedef vec_iterator<T> iterator;
 
   iterator begin();
   iterator end();
@@ -21,6 +24,8 @@ template <typename FwIt, typename Func>
 FwIt remove_if(FwIt begin, FwIt end, Func f);
 
 template <typename FwIt> FwIt unique(FwIt begin, FwIt end);
+
+template <typename T> struct unique_ptr {};
 } // namespace std
 
 struct custom_iter {};
@@ -64,4 +69,9 @@ int main() {
   ERASE(v, 15);
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: this call will remove at most one
   // CHECK-FIXES: {{^  }}ERASE(v, 15);{{$}}
+
+  std::vector<std::unique_ptr<int>> vupi;
+  auto iter = vupi.begin();
+  vupi.erase(iter++);
+  // CHECK-FIXES: {{^  }}vupi.erase(iter++);{{$}}
 }





More information about the cfe-commits mailing list