[clang] [LifetimeSafety] Add fix-it for misplaced lifetimebound attributes (PR #199149)

David Meng via cfe-commits cfe-commits at lists.llvm.org
Wed May 27 06:47:21 PDT 2026


================
@@ -93,10 +115,43 @@ View friend_redecl(MyObj &obj) {
 template <typename T>
 // FIXME: Current analysis suggests adding to the primary template declaration, which is not ideal, as it will affect all specializations.
 MyObj &spec_func(T &obj); // expected-warning {{'lifetimebound' attribute on this definition is not visible to callers before the definition; add it to the declaration instead}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:{{[0-9]+}}-[[@LINE-1]]:{{[0-9]+}}}:" {{\[\[clang::lifetimebound\]\]}}"
 
 template <>
 // FIXME: Attribute is inhetired, diagnostic's wording is not correct.
 MyObj &spec_func<MyObj>(MyObj &obj [[clang::lifetimebound]]); // expected-note {{'lifetimebound' attribute appears here on the definition}}
 
 template <>
 MyObj &spec_func<MyObj>(MyObj &obj) { return obj; }
+
+MyObj get_default_obj();
+const MyObj &default_arg_param(const MyObj&
+    obj  // CHECK: fix-it:"{{.*}}":{[[@LINE]]:{{[0-9]+}}-[[@LINE]]:{{[0-9]+}}}:" {{\[\[clang::lifetimebound\]\]}}"
+    = get_default_obj()); // expected-warning at -2 {{'lifetimebound' attribute on this definition is not visible to callers before the definition; add it to the declaration instead}}
+
----------------
davidmenggx wrote:

I believe I fixed it in the last commit, but updated again to make sure?

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


More information about the cfe-commits mailing list