Author: mboehme Date: Tue Jan 15 23:53:25 2019 New Revision: 351303 URL: http://llvm.org/viewvc/llvm-project?rev=351303&view=rev Log: [clang-tidy] Treat references to smart pointers correctly in use-after-move.
Summary: 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. Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: JonasToth Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D56585 Modified: clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Modified: clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp?rev=351303&r1=351302&r2=351303&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp Tue Jan 15 23:53:25 2019 @@ -207,7 +207,7 @@ void UseAfterMoveFinder::getUsesAndReini } bool isStandardSmartPointer(const ValueDecl *VD) { - const Type *TheType = VD->getType().getTypePtrOrNull(); + const Type *TheType = VD->getType().getNonReferenceType().getTypePtrOrNull(); if (!TheType) return false; Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=351303&r1=351302&r2=351303&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Tue Jan 15 23:53:25 2019 @@ -244,6 +244,19 @@ void standardSmartPtr() { 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. { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits