- Modeling unique_ptr move constructor unique_ptr( unique_ptr&& u ) noexcept
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/test/Analysis/smart-ptr.cpp | ||
---|---|---|
296 | I was trying to test the below code. void foo_() { std::unique_ptr<A> PToMove; std::unique_ptr<A>&& AfterRValeRefCast = std::move(functionReturnsRValueRef()); std::unique_ptr<A> P(AfterRValeRefCast); P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}} } But passing the local RValue reference variable to move constructor is always invoking the deleted copy constructor. |
clang/test/Analysis/smart-ptr.cpp | ||
---|---|---|
296 | Yeah, you still need an explicit move over it. Implicit moves don't happen because it's an rvalue reference, it has more to do with the anonymity of the object; the compiler only auto-moves when there's no possibility for accidental implicit use-after-move, and in presence of a named reference to the value, accidental implicit use-after-move is still very much possible, so an explicit move is required. That's not the exact rules but that's, as far as i understand, the logic behind the exact rules. |
clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp | ||
---|---|---|
456 | Same note tag is used for move assignment and move constructor here. | |
clang/test/Analysis/smart-ptr.cpp | ||
21 | Now both "use after move" and "null pointer dereference" warnings are coming. I hope it will be only "null pointer dereference" after smart pointer modeling is complete |
clang/test/Analysis/smart-ptr.cpp | ||
---|---|---|
296 | Okay |
Same note tag is used for move assignment and move constructor here.