diff options
author | Martin Bohme <mboehme@google.com> | 2019-01-16 07:53:25 +0000 |
---|---|---|
committer | Martin Bohme <mboehme@google.com> | 2019-01-16 07:53:25 +0000 |
commit | 9259c236ce36ac76b8dcc8209f6490c748ec60a5 (patch) | |
tree | 635ae706a890abc4c24b33583298da3b4c9d65e8 | |
parent | 6177eda8577856233853ed2c036617e320c48126 (diff) |
[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
-rw-r--r-- | clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp | 2 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/bugprone-use-after-move.cpp | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp index 11799ebf6d2..99c847ebc46 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp @@ -207,7 +207,7 @@ void UseAfterMoveFinder::getUsesAndReinits( } bool isStandardSmartPointer(const ValueDecl *VD) { - const Type *TheType = VD->getType().getTypePtrOrNull(); + const Type *TheType = VD->getType().getNonReferenceType().getTypePtrOrNull(); if (!TheType) return false; diff --git a/clang-tools-extra/test/clang-tidy/bugprone-use-after-move.cpp b/clang-tools-extra/test/clang-tidy/bugprone-use-after-move.cpp index 59dcb90cb49..dd37aec67b5 100644 --- a/clang-tools-extra/test/clang-tidy/bugprone-use-after-move.cpp +++ b/clang-tools-extra/test/clang-tidy/bugprone-use-after-move.cpp @@ -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. { |