[PATCH] D56585: [clang-tidy] Treat references to smart pointers correctly in use-after-move.

Martin Böhme via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 11 02:13:15 PST 2019


mboehme updated this revision to Diff 181228.
mboehme added a comment.

Removing experimental code that shouldn't have been added.


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56585/new/

https://reviews.llvm.org/D56585

Files:
  clang-tidy/bugprone/UseAfterMoveCheck.cpp
  test/clang-tidy/bugprone-use-after-move.cpp


Index: test/clang-tidy/bugprone-use-after-move.cpp
===================================================================
--- test/clang-tidy/bugprone-use-after-move.cpp
+++ test/clang-tidy/bugprone-use-after-move.cpp
@@ -244,6 +244,19 @@
     std::move(ptr);
     ptr.get();
   }
+  // Make sure we treat references to smart pointers correctly.
+  {
+    std::unique_ptr<A> ptr;
+    std::unique_ptr<A>& ref_to_ptr = ptr;
+    std::move(ref_to_ptr);
+    ref_to_ptr.get();
+  }
+  {
+    std::unique_ptr<A> ptr;
+    std::unique_ptr<A>&& rvalue_ref_to_ptr = std::move(ptr);
+    std::move(rvalue_ref_to_ptr);
+    rvalue_ref_to_ptr.get();
+  }
   // We don't give any special treatment to types that are called "unique_ptr"
   // or "shared_ptr" but are not in the "::std" namespace.
   {
Index: clang-tidy/bugprone/UseAfterMoveCheck.cpp
===================================================================
--- clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -207,7 +207,7 @@
 }
 
 bool isStandardSmartPointer(const ValueDecl *VD) {
-  const Type *TheType = VD->getType().getTypePtrOrNull();
+  const Type *TheType = VD->getType().getNonReferenceType().getTypePtrOrNull();
   if (!TheType)
     return false;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56585.181228.patch
Type: text/x-patch
Size: 1251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190111/ffd2ec64/attachment.bin>


More information about the cfe-commits mailing list