[cfe-dev] Undiagnosed "reference to stack memory [...] returned"

Ted Kremenek kremenek at apple.com
Wed Sep 15 14:19:28 PDT 2010


On Sep 15, 2010, at 12:05 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Wed, Sep 15, 2010 at 11:32 AM, Ted Kremenek <kremenek at apple.com> wrote:
>> I'm not certain this is a bug.  The 'const int&' causes the lifetime of the object returned from get_value() to be extended to its last use.  Does this extend to the caller of get_reference_no_warning_2() since that also returns a const reference?
> 
> In get_reference_no_warning_2, w2 is bound to a temporary which is
> live for the lifetime of w2; returning a reference to the temporary
> doesn't extend its lifetime.
> 
> -Eli

Of course, that makes perfect sense.



More information about the cfe-dev mailing list