[clang] [LifetimeSafety] Warn when lifetimebound attribute is present on the definition but not on declaration (PR #197753)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Fri May 15 07:06:37 PDT 2026


================
@@ -0,0 +1,40 @@
+// RUN: %clang_cc1 -fsyntax-only -Wlifetime-safety-validations -Wno-dangling -verify %s
+
+struct MyObj {
+  ~MyObj() {}
+};
+
+struct S {
+  MyObj data;
+  const MyObj &implicit_this_only(); // expected-warning {{'lifetimebound' attribute on the definition is not visible to callers; add it to this declaration instead}}
+  const MyObj &param_only(const MyObj &obj); // expected-warning {{'lifetimebound' attribute on the definition is not visible to callers; add it to this declaration instead}}
+  const MyObj &both(const MyObj &obj, bool); // expected-warning 2 {{'lifetimebound' attribute on the definition is not visible to callers; add it to this declaration instead}}
----------------
usx95 wrote:

Suggestion for warning text:
`'lifetimebound' attribute should be on the declaration to be visible to callers`

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


More information about the cfe-commits mailing list