This is the mail archive of the gcc@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: Turning warning "returning reference to temporary" into error?


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


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