[fpc-devel] Dangerous optimization in CASE..OF

Florian Klämpfl florian at freepascal.org
Sun Jul 2 20:23:36 CEST 2017


Am 02.07.2017 um 19:55 schrieb Ondrej Pokorny:
> On 02.07.2017 19:29, Martok wrote:
>>  - Case statements execute *precisely one* of their branches: the statements of
>> the matching case label, or the else block otherwise
> 
> To support your argument, the current Delphi documentation says the same:
> 
> http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Declarations_and_Statements
> 
> /Whichever caseList has a value equal to that of selectorExpression determines the statement to be
> used. If none of the caseLists has the same value as selectorExpression, then the statements in the
> else clause (if there is one) are executed./
> 
> According to Delphi documentation, invalid values should point to the else clause.
> 
> Furthermore, it is OK to use invalid values in caseList as well:
> 
> program Project1;
> 
> {$APPTYPE CONSOLE}
> 
> type
>   TMyEnum = (one, two);
> 
> {$R+}
> var
>   E: TMyEnum;
> begin
>   E := TMyEnum(-1);
>   case E of
>     one, two: Writeln('valid');
>     TMyEnum(-1): Writeln('minus one');
>   else
>     Writeln('invalid');
>   end;
> end.
> 
> The program above writes 'minus one' in Delphi.

And the compiler writes no warning during compilation?




More information about the fpc-devel mailing list