Hi djasper,

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(); }

http://reviews.llvm.org/D3540

Files:
  clang-tidy/misc/RedundantSmartptrGet.cpp
  test/clang-tidy/redundant-smartptr-get.cpp

Index: clang-tidy/misc/RedundantSmartptrGet.cpp
===================================================================
--- clang-tidy/misc/RedundantSmartptrGet.cpp
+++ clang-tidy/misc/RedundantSmartptrGet.cpp
@@ -22,6 +22,7 @@
              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");
 }
 
Index: test/clang-tidy/redundant-smartptr-get.cpp
===================================================================
--- test/clang-tidy/redundant-smartptr-get.cpp
+++ test/clang-tidy/redundant-smartptr-get.cpp
@@ -81,6 +81,16 @@
 // 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();
Index: clang-tidy/misc/RedundantSmartptrGet.cpp
===================================================================
--- clang-tidy/misc/RedundantSmartptrGet.cpp
+++ clang-tidy/misc/RedundantSmartptrGet.cpp
@@ -22,6 +22,7 @@
              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");
 }
 
Index: test/clang-tidy/redundant-smartptr-get.cpp
===================================================================
--- test/clang-tidy/redundant-smartptr-get.cpp
+++ test/clang-tidy/redundant-smartptr-get.cpp
@@ -81,6 +81,16 @@
 // 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();
 
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to