[PATCH] D64256: Teach some warnings to respect gsl::Pointer and gsl::Owner attributes

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 7 11:13:37 PDT 2019


xazax.hun marked an inline comment as done.
xazax.hun added inline comments.


================
Comment at: clang/lib/Sema/SemaInit.cpp:7077
+    //   someContainer.add(std::move(localOWner));
+    //   return p;
+    if (!IsTempGslOwner && pathOnlyInitializesGslPointer(Path) &&
----------------
gribozavr wrote:
> 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.
Do you think renaming `localOwner` to `uniquePtr` would be sufficient or do you want me to extend the text too?


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