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?).