This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51270] missed warning about returning reference to temporary
- From: "michiel_dewilde at agilent dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 22 Nov 2011 18:20:44 +0000
- Subject: [Bug c++/51270] missed warning about returning reference to temporary
- Auto-submitted: auto-generated
- References: <bug-51270-4@http.gcc.gnu.org/bugzilla/>
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