On 01/01/2019 22:10, Martok wrote:
The attached patch adds two messages inspired by C compiler's -Wswitch-enum and
-Wcovered-switch-default. Building on the recent label count refactoring, this
was fairly straightforward.

- If a case statement on an ordinal does not contain labels for all values of
the ordinal, and no else statement is given, raise a new warning (W6059). This
is actually defined as an error in ISO7185 and a dynamic-violation in IEC10206.

- If a case statement has labels for the entire range of the type, and an (now
never used) else statement is present, a warning "Unreachable code" is raised.

Thanks. I have added these warnings to the compiler in r42047, and also the static/dynamic errors for Standard resp. Extended ISO Pascal.

By default, the warnings are enabled for
* enums
* boolean
* integer subrange types that don't span the entire range of their storage (e.g. 0..254, -128..0, ..., but not shortint/byte/smallint/word/...)

The warning can be enabled for all ordinal types with the new -CC command line option. Like any other warning, it can be disabled with the corresponding -vm option (-vm6060 in this case).


Jonas
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to