[Bug c++/51270] missed warning about returning reference to temporary

michiel_dewilde at agilent dot com gcc-bugzilla@gcc.gnu.org
Tue Nov 22 18:50:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51270

--- Comment #6 from Michiel De Wilde <michiel_dewilde at agilent dot com> 2011-11-22 18:20:44 UTC ---
Hi Jonathan, thanks for the quick analysis.

I did not realize that "char * &" and "char const * &" are not
reference-compatible, leading to a temporary being introduced when initializing
a "char const * const &" reference from a "char * &".

Therefore this is not a true gcc bug.

It would be nice though to have a warning for this case, i.e. when only the
different constnesses after pointer dereferencing are responsible for
temporaries being created for const lvalue initializations from other lvalues.
I understand this may be difficult.
Improved tracking of the reference to the temporary would also be nice.

Thanks,

Michiel



More information about the Gcc-bugs mailing list