================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to