This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: g++ 2.5.2 does not catch reference to local variable error.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]