This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/19199] [3.3/3.4/4.0 Regression] Wrong warning about returning a reference to a temporary


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]