<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 20, 2013 at 3:38 PM, Joseph Galbraith <span dir="ltr"><<a href="mailto:galb@vandyke.com" target="_blank">galb@vandyke.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all,<br>
<br>
I'm seeing what I think is a spurious warning from this code:<br>
<br>
#include <string><br>
<br>
int<br>
main(int argc, char**)<br>
{<br>
std::wstring x;<br>
auto f = [x] () -> const std::wstring& { return x; };<br>
<br>
return 0;<br>
}<br>
<br>
The warning is:<br>
<br>
stack_local.cpp:7:50: warning: reference to stack memory associated with local variable 'x' returned [-Wreturn-stack-address]<br>
auto f = [x] () -> const std::wstring& { return x; };<br>
<br>
I think since x is actually a lambda capture, not a local variable, it is okay to return its address (so long as the caller finishes with the address before the lambda is destroyed).<br>
<br>
(In my particular use case the lambda lifetime is tied to the callers<br>
lifetime.)<br>
<br>
Is my analysis correct?<br>
<br>
If so, should we suppress this warning for lambda captures?<br></blockquote><div><br></div><div>Yes, and yes. This is <a href="http://llvm.org/PR17374">llvm.org/PR17374</a>. Patches welcome!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Thanks,<br>
<br>
Joseph<br>
<br>
PS. This is from:<br>
<br>
cw01:~ galb$ clang++ --version<br>
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)<br>
Target: x86_64-apple-darwin13.0.0<br>
Thread model: posix<br>
______________________________<u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>