llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LifetimeSafety] False negative on assignment from Owner to Pointer

Open NeKon69 opened this issue 6 months ago • 3 comments

The analysis misses this GSL Pointer assignment case:

struct [[gsl::Owner]] Owner {
  Owner();
};
struct [[gsl::Pointer]] View {
  View();
  View &operator=(const Owner &o [[clang::lifetimebound]]);
  void use() const;
};
void f() {
  View v;
  {
    Owner o;
    v = o;  
  }        // o is destroyed here!
  v.use(); // no warning
}

Expected: warn that o does not live long enough.

https://godbolt.org/z/EMT4WWrnc

NeKon69 avatar May 19 '26 18:05 NeKon69

@llvm/issue-subscribers-clang-temporal-safety

Author: NeKon69

The analysis misses this GSL Pointer assignment case: ```cpp struct [[gsl::Owner]] Owner { Owner(); }; struct [[gsl::Pointer]] View { View(); View &operator=(const Owner &o [[clang::lifetimebound]]); void use() const; }; void f() { View v; { Owner o; v = o; } // o is destroyed here! v.use(); // no warning } ``` Expected: warn that o does not live long enough.

https://godbolt.org/z/EMT4WWrnc

@usx95 Misclick?

NeKon69 avatar May 19 '26 19:05 NeKon69

oops. Yes.

usx95 avatar May 19 '26 19:05 usx95