[clang] [LifetimeSafety] Fix 'clang::lifetimebound' ignored on template method definition (PR #178000)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 26 10:54:23 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
----------------
usx95 wrote:
Wait. That is not the temporary here. For temporaries in lifetime-safety, we need destructors at the moment and `int` lifetimebound wouldn't work. Can you pass `MyObj` as an arg. Also you need to add usage of the pointers after they dangle. Something like `(void) pTMA` would be enough.
https://github.com/llvm/llvm-project/pull/178000
More information about the cfe-commits
mailing list