[PATCH] [clang-tidy] Checker for inaccurate use of erase method.
Alexander Kornienko
alexfh at google.com
Mon Feb 23 05:36:55 PST 2015
REPOSITORY
rL LLVM
================
Comment at: clang-tools-extra/trunk/clang-tidy/misc/InaccurateEraseCheck.cpp:27
@@ +26,3 @@
+
+ Finder->addMatcher(
+ memberCallExpr(
----------------
Interestingly, the matcher also matches this code:
$ cat test.cc
#include <map>
#include <memory>
void f() {
std::map<int, std::unique_ptr<int>> m;
auto iter = m.begin();
m.erase(iter++);
}
$ clang-tidy test.cc -- -std=c++11
...
test.cc:7:3: warning: this call will remove at most one item even when multiple items should be removed [misc-inaccurate-erase]
m.erase(iter++);
^
...
I suspect that getQualifiedNameAsString() for std::unique_ptr<>::operator++ is matched by the "std::unique" part of the regexp. One possible solution is to enclose the regexp in ^$.
http://reviews.llvm.org/D7496
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list