vrnithinkumar marked an inline comment as done. vrnithinkumar added inline comments.
================ Comment at: clang/test/Analysis/smart-ptr.cpp:295 + P->foo(); // No warning. +} ---------------- NoQ wrote: > vrnithinkumar wrote: > > 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. > 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. Okay Thanks for the clarification. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D86373/new/ https://reviews.llvm.org/D86373 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits