[PATCH] D64256: Teach some warnings to respect gsl::Pointer and gsl::Owner attributes
Dmitri Gribenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 6 12:50:10 PDT 2019
gribozavr added inline comments.
================
Comment at: clang/lib/Sema/SemaInit.cpp:7077
+ // someContainer.add(std::move(localOWner));
+ // return p;
+ if (!IsTempGslOwner && pathOnlyInitializesGslPointer(Path) &&
----------------
xazax.hun wrote:
> gribozavr wrote:
> > Why is it a false positive? `std::move` left memory owned by `localOwner` in unspecified state.
> I saw user code relying on the semantics of certain classes. E.g. they assume if a `std::unique_ptr` is moved the pointee is still in place, so it is safe to return a reference to the pointee. Do you think those cases should be diagnosed too?
It is... debatable. It is not obvious whether the lifetime of the pointed-to memory has ended or not without more detailed lifetime annotations. I think it is fair to silence it, however, I think the comment should be updated to explain the situation in a more detailed way, since without context it looks like a use-after-move.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64256/new/
https://reviews.llvm.org/D64256
More information about the cfe-commits
mailing list