Turning warning "returning reference to temporary" into error?

Zack Weinberg zack@codesourcery.com
Sun May 11 20:26:00 GMT 2003


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

zw



More information about the Gcc mailing list