g++ 2.5.2 does not catch reference to local variable error.
Jonathan Wakely
jwakely.gcc@gmail.com
Thu Aug 4 09:54:00 GMT 2011
On 4 August 2011 10:29, Miles Bader wrote:
> Jonathan Wakely <jwakely.gcc@gmail.com> writes:
>>> "g++ -Wall -Wextra ..." should flag a warning on the following code
>>> but does not.
>>
>> Thanks for the apology, but it should still be reported to bugzilla
>> not to this list.
>
> BTW, it should only warn if given -Weffc++, right?
No, returning a reference to a local variable is always wrong, not
only because Meyers says so.
We warn for this unconditionally, without any -W option:
struct XYZ { };
XYZ& f() { XYZ x; return x; }
We just don't do it when the reference doesn't bind directly to the
local, as in the earlier examples, because it's harder.
More information about the Gcc
mailing list