[clang] [LifetimeSafety] Infer [[clang::lifetimebound]] annotation (PR #171081)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 8 01:23:47 PST 2025


================
@@ -552,6 +552,20 @@ const int& get_ref_to_local() {
                       // expected-note at -1 {{returned here}}
 }
 
+View inference_callee_return_identity(View a) {
----------------
usx95 wrote:

```cpp
template<typename T>
T* template_identity(T* a) {
  return a;
}

template<typename T>
T* template_caller(T* a) {
  return template_identity(a);
}

MyObj* test_template_inference_with_stack() {
  MyObj local_stack;
  return template_caller(&local_stack);     // expected-warning {{address of stack memory is returned later}}
                                            // expected-note at -1 {{returned here}}
  
}

```

(I think this might not work due to instantiations being deferred to the end of TU)

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


More information about the cfe-commits mailing list