[fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

Ondrej Pokorny lazarus at kluug.net
Sun May 12 17:14:41 CEST 2019

On 12.05.2019 16:36, Jonas Maebe wrote:
> Thanks. I have added these warnings to the compiler in r42047, and 
> also the static/dynamic errors for Standard resp. Extended ISO Pascal.

Very nice.

One question about "C-style enumeration types" 

Do the holes between undefined enum values belong to the enumeration or 
not? Because:

1.) The FPC documentation states they do not. See 
/"The Pred and Succ functions cannot be used on this kind of enumeration 
types. Trying to do this anyhow will result in a compiler error."/

2.) The Delphi documentation states they do. See 
/"An enumerated type is, in effect, a subrange whose lowest and highest 
values correspond to the lowest and highest ordinalities of the 
constants in the declaration."/

3.) Your newly added warnings indicate they do. Because a warning is 
emitted if all well-defined values are used in the case statement:

program Project1;
{$mode objfpc}
   TMyEnum = (one = 2, two = 5);
   A: TMyEnum;
   A := TMyEnum(3);
   case A of // compiler warning: Case statement does not handle all 
possible cases
     one: Exit;
     two: Exit;
   Writeln(A); // run-time error 107 - so maybe not a possible case 
after all?


This dissimilarities should get resolved.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190512/cccbde6e/attachment.html>

More information about the fpc-devel mailing list