This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Warn when returning the address of a temporary (middle-end)
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Marc Glisse <marc dot glisse at inria dot fr>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 30 Apr 2014 22:39:19 +0000
- Subject: Re: Warn when returning the address of a temporary (middle-end)
- Authentication-results: sourceware.org; auth=none
- References: <alpine dot DEB dot 2 dot 02 dot 1404051508500 dot 22861 at stedding dot saclay dot inria dot fr>
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