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

llvm-svn: 230483
This commit is contained in:
Gabor Horvath 2015-02-25 12:17:03 +00:00
parent addb2daaac
commit ca0bbff3a7
2 changed files with 14 additions and 4 deletions

View File

@ -26,10 +26,10 @@ void InaccurateEraseCheck::registerMatchers(MatchFinder *Finder) {
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);

View File

@ -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++);{{$}}
}