[Bug c++/60517] warning/error for taking address of member of a temporary object
manu at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 14 16:51:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60517
--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #6)
> (In reply to Marc Glisse from comment #5)
> > I would need a different (middle-end) warning that
> > detects return &local_var,
>
> To confirm this, I looked at the last dangling reference I debugged,
> recompiled it with -O3 -fkeep-inline-functions, and a grep for "return &" in
> the .optimized dump showed:
> return &one;
> return &one;
> return &D.495451.c_;
> (where "one" is a global variable, but D.495451 is a local variable)
> so even this trivial version of the warning would be useful.
To avoid duplicates, the front-end could just return something else, like NULL,
when it detects this case (I guess the behavior is undefined and we can do
whatever we want, no?).
More information about the Gcc-bugs
mailing list