Hi Argyrios,<br><br>Thank you very much!<br><br>It's great that clang will diagnose this UB, it's a really nasty bug to track down :)<br><br>Matthieu.<br><br><div class="gmail_quote">2010/11/29 Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com">akyrtzi@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Matthieu,<div><br></div><div>Sorry for the (very..) late response. We now warn for all cases since <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20101129/036838.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20101129/036838.html</a></div>

<div><br></div><div>Thanks for reporting the issue!</div><div><br></div><div>-Argiris<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Wed, Sep 15, 2010 at 11:04 AM, Matthieu Monrocq <span dir="ltr"><<a href="mailto:matthieu.monrocq@gmail.com" target="_blank">matthieu.monrocq@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">Hi guys,<br><br>here is a very simple test case:<br>
<br>    int const& get_reference_warning()<br>    {<br>      int w = 0;<br>
      return w; // expected-warning{{reference to stack memory associated with local variable 'w' returned}}<br>
    }<br><br>    int get_value();<br><br>    int const& get_reference_no_warning() { return get_value(); } // Diagnosed by VC++ 2010 (haven't tested on gcc), but unnoticed by Clang<br><br>    int const& get_reference_no_warning_2()<br>


    {<br>      int const& w2 = get_value();         // Correct, lifetime of the value is extended to the lifetime of the const reference<br>      return w2;                                   // Undefined behavior: goes unnoticed by Clang, VC++ 2010 and gcc 3.4.2<br>


    }<br><br>I compiled it with:   clang.exe -fsyntax-only -Wall -pedantic test.cpp   (on Windows, using PowerShell)<br><br>    test.cpp(9) :  warning: reference to stack memory associated with local variable 'w' returned<br>


      return w; // expected-warning{{reference to stack memory associated with local variable 'w' returned}}<br>         ^<br>    1 warning generated.<br><br>As expected, the first return provoked a warning.<br><br>


However in the two other cases, no warning is generated.<br><br>I was wondering if it would be possible for clang to diagnose those cases as well. I guess the third case is the trickier, though since the lifetime of the value is correctly extended, therre should be a way to detect that `w2` is not just an ordinary const reference. I must admit I haven't come over the Clang code base yet so it's still a bit blurry to me (by the way if someone could kindly point me to some doc for developers...)<br>


<br>Should I file a bug ? (or perhaps one already exists...)<br><font color="#888888"><br>Matthieu.<br>
</font><br></div></div><div class="im">_______________________________________________<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/mailman/listinfo/cfe-dev</a><br>
<br></div></blockquote></div><br></div>
</blockquote></div><br>