[clang] [LifetimeSafety] Use buildOriginFlowChain for remaining diagnostics in issuePendingWarnings (PR #212083)
Yuan Suo via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 22 01:44:40 PDT 2026
================
@@ -2337,8 +2374,9 @@ auto capture_int_by_value() {
auto capture_view_by_value() {
MyObj obj;
View v(obj); // expected-warning {{stack memory associated with local variable 'obj' is returned}}
- auto lambda = [v]() { return v; };
- return lambda; // expected-note {{returned here}}
+ auto lambda = [v]() { return v; }; // expected-note {{local variable 'v' aliases the storage of local variable 'obj'}}
+ return lambda; // expected-note {{returned here}} \
+ // expected-note {{local variable 'lambda' aliases the storage of local variable 'obj'}}
----------------
suoyuan666 wrote:
Maybe I'm misunderstanding something. Do you mean I need to write it like this?
```cpp
auto capture_view_by_value() {
MyObj obj;
View v(obj); // expected-warning {{stack memory associated with local variable 'obj' is returned}}
auto lambda = [v]() { return v; }; // expected-note {{local variable 'v' aliases the storage of local variable 'obj'}}
return lambda; // expected-note {{returned here}} \
// expected-note {{local variable 'lambda' aliases the storage of local variable 'obj'}}
}
```
https://github.com/llvm/llvm-project/pull/212083
More information about the cfe-commits
mailing list