summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp10
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp15
2 files changed, 20 insertions, 5 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 158fe2e37e8..e3686359fa0 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -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(),
diff --git a/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp
index 701b9defc40..61a36f6dee3 100644
--- a/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp
+++ b/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp
@@ -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();
OpenPOWER on IntegriCloud