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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits