mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 01:29:52 +00:00
[clang-tidy] Match the type against the get() method we are calling,
instead of a get() method we find in the class. The duck typed smart pointer class could have overloaded get() methods and we should only skip the one that matches. llvm-svn: 261102
This commit is contained in:
parent
07d72f4f49
commit
1fb8bc7a30
@ -25,7 +25,9 @@ internal::Matcher<Expr> callToGet(internal::Matcher<Decl> OnClass) {
|
||||
pointsTo(decl(OnClass).bind("ptr_to_ptr"))))))
|
||||
.bind("smart_pointer")),
|
||||
unless(callee(memberExpr(hasObjectExpression(cxxThisExpr())))),
|
||||
callee(cxxMethodDecl(hasName("get"))))
|
||||
callee(cxxMethodDecl(
|
||||
hasName("get"),
|
||||
returns(qualType(pointsTo(type().bind("getType")))))))
|
||||
.bind("redundant_get");
|
||||
}
|
||||
|
||||
@ -35,10 +37,8 @@ void registerMatchersForGetArrowStart(MatchFinder *Finder,
|
||||
recordDecl().bind("duck_typing"),
|
||||
has(cxxMethodDecl(hasName("operator->"),
|
||||
returns(qualType(pointsTo(type().bind("op->Type")))))),
|
||||
has(cxxMethodDecl(hasName("operator*"),
|
||||
returns(qualType(references(type().bind("op*Type")))))),
|
||||
has(cxxMethodDecl(hasName("get"),
|
||||
returns(qualType(pointsTo(type().bind("getType")))))));
|
||||
has(cxxMethodDecl(hasName("operator*"), returns(qualType(references(
|
||||
type().bind("op*Type")))))));
|
||||
|
||||
// Catch 'ptr.get()->Foo()'
|
||||
Finder->addMatcher(memberExpr(expr().bind("memberExpr"), isArrow(),
|
||||
|
@ -44,6 +44,14 @@ struct Fail2 {
|
||||
int& operator*();
|
||||
};
|
||||
|
||||
struct PointerWithOverloadedGet {
|
||||
int* get();
|
||||
template <typename T>
|
||||
T* get();
|
||||
int* operator->();
|
||||
int& operator*();
|
||||
};
|
||||
|
||||
void Positive() {
|
||||
BarPtr u;
|
||||
// CHECK-FIXES: BarPtr u;
|
||||
@ -100,6 +108,11 @@ void Positive() {
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
|
||||
// CHECK-MESSAGES: nullptr != ss->get();
|
||||
// CHECK-FIXES: bb = nullptr != *ss;
|
||||
|
||||
i = *PointerWithOverloadedGet().get();
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
|
||||
// CHECK-MESSAGES: i = *PointerWithOverloadedGet().get();
|
||||
// CHECK-FIXES: i = *PointerWithOverloadedGet();
|
||||
}
|
||||
|
||||
void Negative() {
|
||||
@ -113,6 +126,8 @@ void Negative() {
|
||||
}
|
||||
};
|
||||
|
||||
long l = *PointerWithOverloadedGet().get<long>();
|
||||
|
||||
std::unique_ptr<Bar>* u;
|
||||
u->get()->Do();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user