[clang] [Lifetime] Fix 'clang::lifetimebound' ignored on template method definition (PR #178000)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 26 09:32:24 PST 2026


================
@@ -1260,13 +1278,17 @@ void test() {
 
     // Templated tests (generic templates)
     const auto ptrTA = StringTemplateA<char>().data();  // Declaration-only attribute // expected-warning {{temporary whose address is used}}
-    // FIXME: Definition is not instantiated until the end of TU. The attribute is not merged when this call is processed.
-    const auto ptrTB = StringTemplateB<char>().data();  // Definition-only attribute
+    const auto ptrTB = StringTemplateB<char>().data();  // Definition-only attribute  // expected-warning {{temporary whose address is used}}
     const auto ptrTC = StringTemplateC<char>().data();  // Both have attribute        // expected-warning {{temporary whose address is used}}
 
     // Template specialization tests
     const auto ptrTSA = StringTemplateSpecA<char>().data();  // Declaration-only attribute  // expected-warning {{temporary whose address is used}}
     const auto ptrTSB = StringTemplateSpecB<char>().data();  // Definition-only attribute   // expected-warning {{temporary whose address is used}}
     const auto ptrTSC = StringTemplateSpecC<char>().data();  // Both have attribute         // expected-warning {{temporary whose address is used}}
+
+    MemberFuncsTpl<int> mtf;
+    const int* pTMA = mtf.memberA(1);  // Declaration-only attribute  // expected-warning {{temporary whose address is used}}
+    const int* pTMB = mtf.memberB(2);  // Definition-only attribute   // FIXME: Definition-only attribute
----------------
vbvictor wrote:

Added a fixme case here, as I understand this should be diagnosed too.
I suppose this will need adjustments here
https://github.com/vbvictor/llvm-project/blob/main/clang/lib/Sema/CheckExprLifetime.cpp#L503

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


More information about the cfe-commits mailing list