wrong const enum case optimization
Original Reporter info from Mantis: UK
-
Reporter name: UK
Original Reporter info from Mantis: UK
- Reporter name: UK
Description:
Even if it doesn’t make sense on the first view to program a constant decision case block, since the case value is constant, the compiler reduces the case block to one case statement but chose the wrong one if the alternatives are listed in a (wrong) sort order (e.g.: a-c-b).
- no additional optimization level is used
- observed in windows/i386 environment but might be independent
The sample program runs the else statement and shows the '?'.
Steps to reproduce:
program test;
type
E = ( a, b, c );
begin
case b of
a: write( 'a' );
c: write( 'c' );
b: write( 'b' );
else write( '?' );
end;
end;
Additional information:
workaround: Use a variable case value in order to avoid the optimization.
1.) const
S: E = b;
...
case S of ...
2.) var
S: E;
...
S := b
case S of ...
Mantis conversion info:
- Mantis ID: 30522
- Build: SVN:33143
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 34379 (#3669419b)