Consider the example: auto test(int s) { return [&s] { return s; }; } `s` is a local variable, so we return a lambda that has a dangling reference. It would be nice to have a warning for such cases.
(In reply to Antony Polukhin from comment #0) > Consider the example: > > auto test(int s) { > return [&s] { return s; }; > } > > > `s` is a local variable, so we return a lambda that has a dangling reference. > > It would be nice to have a warning for such cases. Under -Wreturn-local-addr, or a new flag?
-Wreturn-local-addr looks good to me
(In reply to Antony Polukhin from comment #2) > -Wreturn-local-addr looks good to me Hm, I suddenly got the idea that there was another bug under the -Wreturn-local-addr meta-bug that this might be a dup of, but after checking, it doesn't look like it after all... confirmed as a separate bug for now, I guess.
(In reply to Eric Gallager from comment #3) > (In reply to Antony Polukhin from comment #2) > > -Wreturn-local-addr looks good to me > > Hm, I suddenly got the idea that there was another bug under the > -Wreturn-local-addr meta-bug that this might be a dup of, but after > checking, it doesn't look like it after all... confirmed as a separate bug > for now, I guess. I guess it might have been bug 70692 that I was thinking of? But that's a different -Wreturn-local-addr issue; it's only related enough for the "See Also" field...
Dup of bug 84544. *** This bug has been marked as a duplicate of bug 84544 ***