[fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements
Jonas Maebe
jonas at freepascal.org
Sun May 12 19:56:34 CEST 2019
On 12/05/2019 19:39, Ondrej Pokorny wrote:
> On 12.05.2019 18:56, Jonas Maebe wrote:
>> As far as range checking and undefined behaviour is concerned, they
>> do. I.e., you won't get undefined behaviour by assigning any value
>> between low(enum)..high(enum) to them.
>
> Very good, thank you. IMO this should be clearly documented to avoid
> confusion.
True.
> And if they are valid they should not cause any runtime errors:
>
> program Project1;
> {$mode objfpc}
> type
> TMyEnum = (two=2, five=5);
> var
> E: TMyEnum;
> begin
> E := TMyEnum(3);
> Writeln(E); // RunError (107)
> end.
>
> (From the above example one would say they are not valid.)
write(enum) is an FPC extension. It writes out the declared enum
identifier. There is none in this case, so a run time error is appropriate.
> There was a misunderstanding. I thought you meant with "implicit" values
> the "implicit default values" (=0):
>
> program Project1;
> {$mode objfpc}
> type
> TMyEnum = (two=2, five=5);
> TMyObject = class
> E: TMyEnum;
> end;
> var
> O: TMyObject;
> begin
> O := TMyObject.Create;
> Writeln(Ord(O.E)); // R has an implicit default valuethat is invalid
> ReadLn;
> end.
>
> But you meant the implicit valid values (the holes). Now it's clear.
Ah, indeed.
Jonas
More information about the fpc-devel
mailing list