[fpc-devel] Unreachable code warnings
daniel.mantione at freepascal.org
Sun Oct 14 19:56:47 CEST 2007
Op Sun, 14 Oct 2007, schreef Micha Nelissen:
> I want to bring up the warning of unreachable code. If one is
> implementing code according to some spec, e.g. RFC, or what else, it
> occurs that that requires a sanity check on user input. If it now
> happens that the type of variable by accident guarantees that this is
> true; this is fine, the compiler might optimize the check away. The
> compiler should not give a warning though IMHO, because the check is
> necessary according to spec, and it might become necessary if someone
> decides to change the type of the variable being checked to have a wider
> range. Furthermore, the warning is not suppressible.
You mean this:
if (b<0) or (b>255) then
writeln('Error: Invalid value');
IMO the compiler in the case above totally correct to let you know the
error condition can never occur. Even if a specification says 255 is the
maximum, the code is totally bogus.
It is justified to warn, since in some cases an error situation can occur
but the way the check is written causes a dead code check. We found a few
of these in the compiler sources.
More information about the fpc-devel