This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Turning warning "returning reference to temporary" into error?
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>, <gcc at gcc dot gnu dot org>
- Date: Sun, 11 May 2003 22:43:40 +0200 (CEST)
- Subject: Re: Turning warning "returning reference to temporary" into error?
On Sun, 11 May 2003, Zack Weinberg wrote:
> Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
>
> > A compiler writer cannot imagine every possible usage. Which is why
> > somethings are warnings. In this case, if the return value is ignored
> > then the program is valid. GCC cannot reject it just because
> > -pedantic is specified.
>
> In other places where we can prove that execution of a certain code
> path will cause undefined behavior, but we can't prove that that path
> will be taken at runtime, we issue a warning and generate a trap
> instruction. An analogous tactic for this scenario would be if we
> generated code to return a distinguished pointer value that's
> guaranteed to cause a segmentation fault when dereferenced. (This
> should _not_ be 0, as that may mask the bug.)
I really want this to be diagnosed at compile time, and as this is a large
project, I want to have an error diagnosed, not only a warning. In the
current form this is not possible without turning every default warning
into an error with -Werror. Can we do something about this? I can come up
with a patch, but I neither have a copyright assignment, nor experience
with hacking gcc. At least, would a -Wreturn, default on, warning option
be ok, so I can use -w -Wreturn -Werror (will this work?) to make this an
error?
Thanks, Richard.