[fpc-devel] Data flow analysis (dfa) and "case ... of"
dezlov at gmail.com
Mon Jun 5 21:44:27 CEST 2017
On 05/06/2017 19:49, Jonas Maebe wrote:
> The DFA simply does not take into account the result of
> case-statements at all right now. If you have a "case bytevar of" with
> every possible value from 0 to 255, you will still get the warning.
On 05/06/2017 19:43, Sven Barth wrote:
> They are legal in the sense that they result in undefined behavior and
> in that case the compiler is free to act as it sees fit.
By covering all possible cases I meant including "else" condition in all
case statements, which either defaults to some acceptable value or
raises an exception to highlight an invalid value. This is just a
standard practice for me, so my code never produces "uninitialized
result" warnings, unless I actually made a mistake by not covering all
possible cases, in which case I would really like to see that warning no
matter what. I prefer to see a controlled exception instead of having an
invalid value producing a pseudo-valid semi-random result which may be
much more difficult to trace later.
Complier currently warns (cares) about such execution flows which are
triggered by invalid data, and I happen to find it useful :)
However, I do understand that compiler can rightfully not care about
invalid data, hence, choose not to issue the "uninitialized result"
warning if all valid values have been enumerated.
More information about the fpc-devel