[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 ¶m_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}}
+};
+
+const MyObj &S::implicit_this_only() [[clang::lifetimebound]] { // expected-note {{'lifetimebound' attribute written on the definition is here}}
----------------
usx95 wrote:
Suggestion for note text:
`'lifetimebound' attribute appears here on the definition`
https://github.com/llvm/llvm-project/pull/197753
More information about the cfe-commits
mailing list