diff options
author | Samuel Benzaquen <sbenza@google.com> | 2014-04-29 13:41:23 +0000 |
---|---|---|
committer | Samuel Benzaquen <sbenza@google.com> | 2014-04-29 13:41:23 +0000 |
commit | 20e93f39c1bfd578f7069ae19a8844a852b63115 (patch) | |
tree | 144269530e7c7af24deb949c697b936f719d0de4 | |
parent | b3268e71e2f3476872860bc5b61172f8086fbb50 (diff) | |
download | bcm5719-llvm-20e93f39c1bfd578f7069ae19a8844a852b63115.tar.gz bcm5719-llvm-20e93f39c1bfd578f7069ae19a8844a852b63115.zip |
Do not touch get() calls on 'this' object.
Summary:
These calls are part of the implementation of the smart pointer itself
and chaning it is likely to be wrong.
Example:
T& operator*() const { return *get(); }
Reviewers: djasper
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3540
llvm-svn: 207525
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/RedundantSmartptrGet.cpp | 1 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/redundant-smartptr-get.cpp | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/RedundantSmartptrGet.cpp b/clang-tools-extra/clang-tidy/misc/RedundantSmartptrGet.cpp index 97398af2977..d48d74c1125 100644 --- a/clang-tools-extra/clang-tidy/misc/RedundantSmartptrGet.cpp +++ b/clang-tools-extra/clang-tidy/misc/RedundantSmartptrGet.cpp @@ -22,6 +22,7 @@ internal::Matcher<Expr> callToGet(internal::Matcher<Decl> OnClass) { on(expr(anyOf(hasType(OnClass), hasType(qualType(pointsTo(decl(OnClass).bind( "ptr_to_ptr")))))).bind("smart_pointer")), + unless(callee(memberExpr(hasObjectExpression(thisExpr())))), callee(methodDecl(hasName("get")))).bind("redundant_get"); } diff --git a/clang-tools-extra/test/clang-tidy/redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/redundant-smartptr-get.cpp index 3887f8e522d..091e9d4dc68 100644 --- a/clang-tools-extra/test/clang-tidy/redundant-smartptr-get.cpp +++ b/clang-tools-extra/test/clang-tidy/redundant-smartptr-get.cpp @@ -81,6 +81,16 @@ void Positive() { // CHECK-NOT: warning void Negative() { + struct NegPtr { + int* get(); + int* operator->() { + return &*this->get(); + } + int& operator*() { + return *get(); + } + }; + std::unique_ptr<Bar>* u; u->get()->Do(); |