This is the mail archive of the gcc-patches@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]

Re: Warn when returning the address of a temporary (middle-end)


On Sat, 5 Apr 2014, Marc Glisse wrote:

> One hard part is avoiding duplicate warnings. Replacing the address with 0 is
> a convenient way to do that, so I did it both for my new warning and for the
> existing C/C++ ones. The patch breaks gfortran.dg/warn_target_lifetime_2.f90

That's not safe the way you do it; you lose side effects from the original 
return value.  Consider a testcase such as:

extern void exit (int);
extern void abort (void);

int *
f (void)
{
  int a[10];
  return &a[(exit (0), 0)];
}

int
main (void)
{
  f ();
  abort ();
}

(which produces the existing warning, but which has behavior fully defined 
to exit with status 0).

-- 
Joseph S. Myers
joseph@codesourcery.com


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