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

Martin Böhme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 15 23:57:18 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL351303: [clang-tidy] Treat references to smart pointers correctly in use-after-move. (authored by mboehme, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D56585

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


Index: clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/trunk/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;
 
Index: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
+++ clang-tools-extra/trunk/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.
   {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56585.181979.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190116/f31f088f/attachment-0001.bin>


More information about the llvm-commits mailing list