Turning warning "returning reference to temporary" into error?
Richard Guenther
rguenth@tat.physik.uni-tuebingen.de
Sun May 11 20:44:00 GMT 2003
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.
More information about the Gcc
mailing list