This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/19199] [3.3/3.4/4.0 Regression] Wrong warning about returning a reference to a temporary
- From: "amylaar at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Jan 2005 18:02:04 -0000
- Subject: [Bug c++/19199] [3.3/3.4/4.0 Regression] Wrong warning about returning a reference to a temporary
- References: <20041230105911.19199.lars@trolltech.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From amylaar at gcc dot gnu dot org 2005-01-26 18:02 -------
Is the folowing the same bug?
extern void abort (void);
int i0 = 999;
int *const p = &i0;
int const *const &
foo ()
{
return p;
}
int
main ()
{
int i = *foo ();
if (i != i0)
abort ();
return 0;
}
This warns, and fails at -O1. At -O0 the code is also wrong, but it passes
because the assignment to the stack temporary happens, and the stack is not
scribbled over.
If I make the creation of a const * const & temporary explicit, the warning
is not emitted, but the code is still wrong in the same way:
extern void abort (void);
int i0 = 999;
int *const p = &i0;
int const *const &
foo ()
{
int const *const &p0 = p;
return p0;
}
int
main ()
{
int i = *foo ();
if (i != i0)
abort ();
return 0;
}
If I define p instead with
int const *const p = &i0;
no bogus temporary is generated.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19199