[clang] [clang] Respect the lifetimebound in assignment operator. (PR #106997)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 2 08:31:55 PDT 2024


================
@@ -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:

Oh, never mind. Actually, in that specialization people would not mark the argument of `operator=` lifetimebound. This makes total sense. Disregard this. 

https://github.com/llvm/llvm-project/pull/106997


More information about the cfe-commits mailing list