<div dir="ltr">Hiya,<div><br></div><div>I ran into this (presumably) undefined behaviour today, and wonder if it's a bug or expected. My app was coded similarly and ran correctly on macOS/LLVM version 8.1.0 (clang-802.0.38) but not Ubuntu14.04/gcc-4.7.3-12ubuntu1</div><div><br></div><div>In the case of this code, it's invalid since the lambda returns a reference to a temp object. My bad, I'll fix it. Seems the compiler could've warned me though :)</div><div><br></div><div>Compiler warns when explicitly specifying the return type of the lambda using `->` operator, but not when implicit. Is this expected or a bug?</div><div><br></div><div>Thanks in advance,</div><div>Matt</div><div><br></div><div>// Minimal test case:</div><div>





<p class="inbox-inbox-p1"><span class="inbox-inbox-s1">#include </span><span class="inbox-inbox-s2"><functional></span></p>
<p class="inbox-inbox-p1"><span class="inbox-inbox-s1">#include </span><span class="inbox-inbox-s2"><iostream></span></p>
<p class="inbox-inbox-p2"><span class="inbox-inbox-s2"></span><br></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s3">void</span><span class="inbox-inbox-s2"> print_stuff(</span><span class="inbox-inbox-s4">std</span><span class="inbox-inbox-s2">::</span><span class="inbox-inbox-s5">function</span><span class="inbox-inbox-s2"><</span><span class="inbox-inbox-s3">const</span><span class="inbox-inbox-s2"> </span><span class="inbox-inbox-s3">int</span><span class="inbox-inbox-s2">&()> f) {</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2"><span class="inbox-inbox-Apple-converted-space">    </span></span><span class="inbox-inbox-s4">std</span><span class="inbox-inbox-s2">::</span><span class="inbox-inbox-s4">cout</span><span class="inbox-inbox-s2"> << </span><span class="inbox-inbox-s6">"stuff is: "</span><span class="inbox-inbox-s2"> << f() << </span><span class="inbox-inbox-s4">std</span><span class="inbox-inbox-s2">::</span><span class="inbox-inbox-s7">endl</span><span class="inbox-inbox-s2">;</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2">}</span></p>
<p class="inbox-inbox-p2"><span class="inbox-inbox-s2"></span><br></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s3">int</span><span class="inbox-inbox-s2"> main(</span><span class="inbox-inbox-s3">int</span><span class="inbox-inbox-s2"> argc, </span><span class="inbox-inbox-s3">char</span><span class="inbox-inbox-s2"> *argv[]) {</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2"><span class="inbox-inbox-Apple-converted-space">    </span></span><span class="inbox-inbox-s8">print_stuff</span><span class="inbox-inbox-s2">([]() {</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2"><span class="inbox-inbox-Apple-converted-space">        </span></span><span class="inbox-inbox-s3">int</span><span class="inbox-inbox-s2"> i = </span><span class="inbox-inbox-s9">123</span><span class="inbox-inbox-s2">;</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2"><span class="inbox-inbox-Apple-converted-space">        </span></span><span class="inbox-inbox-s3">return</span><span class="inbox-inbox-s2"> i;</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2"><span class="inbox-inbox-Apple-converted-space">    </span>});</span></p>
<p class="inbox-inbox-p3"><span class="inbox-inbox-s2">}</span></p></div></div>