------- 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