[clang] [LifetimeSafety] Merge lifetimebound attribute on implicit 'this' across method redeclarations (PR #172146)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 14 01:57:55 PST 2025


================
@@ -75,6 +75,18 @@ namespace usage_ok {
     r = A(1); // expected-warning {{object backing the pointer 'r' will be destroyed at the end of the full-expression}}
   }
 
+  // Test that lifetimebound on implicit 'this' is propagated across redeclarations
+  struct B {
+    int *method() [[clang::lifetimebound]];
+    int i;
+  };
+  int *B::method() { return &i; }
----------------
cor3ntin wrote:

Can you add a test for that?

```cpp
  struct B {
    int *method();
    int i;
  };
  int *B::method() [[clang::lifetimebound]]; { return &i; }
```


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


More information about the cfe-commits mailing list