================ @@ -287,3 +287,18 @@ std::span<int> test2() { return abc; // expected-warning {{address of stack memory associated with local variable}} } } // namespace ctor_cases + +namespace GH106372 { +class [[gsl::Owner]] Foo {}; +class [[gsl::Pointer]] FooView {}; + +template <typename T> +struct StatusOr { + template <typename U = T> + StatusOr& operator=(U&& v [[clang::lifetimebound]]); +}; + +void test(StatusOr<FooView> foo) { + foo = Foo(); // expected-warning {{object backing the pointer foo will be destroyed at the end}} ---------------- Xazax-hun wrote:
I am actually a bit split on this code snippet. I think this is probably fine in most cases, but I wonder if this is prone to false positives. We only know that `FooView` is a pointer, but strictly speaking we have no idea what `StatusOr` is doing. We could have an explicit specialization for `StatusOr<FooView>` that actually stores a `Foo` inside instead of `FooView`. Is that good practice? Absolutely not. I am just wondering if this is justified enough for an on by default warning. (Same goes for the initialization case, not just the assignment.) https://github.com/llvm/llvm-project/pull/106997 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits