[fpc-devel] "Case statement does not handle all possible cases" Warning
Ondrej Pokorny
lazarus at kluug.net
Sun May 19 17:42:19 CEST 2019
On 19.05.2019 09:34, Sven Barth via fpc-devel wrote:
> J. Gareth Moreton <gareth at moreton-family.com
> <mailto:gareth at moreton-family.com>> schrieb am So., 19. Mai 2019, 05:17:
>
> I just feel that in this case, it should be a note, not a warning,
> unless you're compiling under a dialect of Pascal (e.g. Extended)
> that
> is stricter in its interpretation of the whitesheet and demands an
> error
> be returned.
>
>
> No, I don't think so. The compiler might generate quite some hints and
> notes some of which might be false positives (take the "uninitialized
> variable" in context of "var" parameters) and thus this note/hint
> would be lost among the noise.
What makes you think an incomplete case statement might not be a false
positive?
> Also you need to keep in mind that enums are not necessarily static
> over the lifetime of the software. E.g. (using the compiler as an
> example) a new def type could be added. If you now haven't added empty
> else-clauses to the case-statements you'll now get a nice warning for
> every such case statement so that you can be reasonably sure you
> caught all.
A note would do just the same.
That all said, I very much like this new enum warning. A note would just
do the same job (and I don't care if it's a warning or a note).
> At my work (where we use MSVC) we enabled the compiler's warning for
> this reason.
In FPC we needed such a construct at every case block
{$IF (Ord(High(TMyEnum)) <> 2)} {$MESSAGE Warning 'Case does not
respond to all possible values'} {$IFEND}
to get a warning when a new enum value is added. We don't need it
anymore, good.
Ondrej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190519/626b5616/attachment.html>
More information about the fpc-devel
mailing list