[clang-tools-extra] r207525 - Do not touch get() calls on 'this' object.

Samuel Benzaquen sbenza at google.com
Tue Apr 29 06:41:23 PDT 2014


Author: sbenza
Date: Tue Apr 29 08:41:23 2014
New Revision: 207525

URL: http://llvm.org/viewvc/llvm-project?rev=207525&view=rev
Log:
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

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/RedundantSmartptrGet.cpp
    clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/RedundantSmartptrGet.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/RedundantSmartptrGet.cpp?rev=207525&r1=207524&r2=207525&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/RedundantSmartptrGet.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/RedundantSmartptrGet.cpp Tue Apr 29 08:41:23 2014
@@ -22,6 +22,7 @@ internal::Matcher<Expr> callToGet(intern
              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");
 }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp?rev=207525&r1=207524&r2=207525&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/redundant-smartptr-get.cpp Tue Apr 29 08:41:23 2014
@@ -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();
 





More information about the cfe-commits mailing list