[PATCH] D86373: [analyzer] Add modeling for unique_ptr move constructor

Nithin VR via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 26 13:32:17 PDT 2020


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



More information about the cfe-commits mailing list