[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:09:37 PST 2019
mboehme created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Previously, we weren't recognizing these as smart pointers and thus
weren't allowing non-dereference accesses as we should -- see new test
cases which fail without the fix.
Repository:
rCTE Clang Tools Extra
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.
{
@@ -257,6 +270,11 @@
}
}
+void foo(std::unique_ptr<A>&& a) {
+ std::move(a);
+ std::move(a);
+}
+
// The check also works in member functions.
class Container {
void useAfterMoveInMemberFunction() {
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.181227.patch
Type: text/x-patch
Size: 1463 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190111/16242dca/attachment.bin>
More information about the cfe-commits
mailing list