[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"
https://www.freepascal.org/docs-html/ref/refse12.html#QQ2-26-31
Do the holes between undefined enum values belong to the enumeration or
not? Because:
1.) The FPC documentation states they do not. See
https://www.freepascal.org/docs-html/ref/refse12.html#QQ2-26-31
/"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
http://docwiki.embarcadero.com/RADStudio/Rio/en/Simple_Types_(Delphi)#Enumerated_Types_with_Explicitly_Assigned_Ordinality
/"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}
type
TMyEnum = (one = 2, two = 5);
var
A: TMyEnum;
begin
A := TMyEnum(3);
case A of // compiler warning: Case statement does not handle all
possible cases
one: Exit;
two: Exit;
end;
Writeln(A); // run-time error 107 - so maybe not a possible case
after all?
ReadLn;
end.
---
This dissimilarities should get resolved.
Ondrej
-------------- 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