View Issue Details

IDProjectCategoryView StatusLast Update
0036974FPCCompilerpublic2020-04-28 10:50
ReporterIan Hickson Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Summary0036974: "Warning: Case statement does not handle all possible cases" does not handle non-sequential enums
DescriptionIn the following program, the "Warning: Case statement does not handle all possible cases" message is emitted by the compiler, even though every value is listed in the case statement.

The problem occurs any time the enum is not sequential. For example, if b=2 in the type declaration, it works fine.

program main;
type
   TTest = (a = 1, b = 3);
var
   Foo: TTest = a;
begin
   case (Foo) of
      a: ;
      b: ;
   end;
end.


By the way, I love this warning in general. It found a bunch of bugs and made it possible to clean out a bunch of dead code. Thanks for adding it!
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

nanobit

2020-04-26 07:55

reporter   ~0122434

Last edited: 2020-04-26 08:06

View 2 revisions

All values within Tenum bounds are defined, but not named. Thus you need "else".
You could view unnamed as reserved.

And specific to FPC implementation, defined input is needed to prevent:
Case-statement can crash before reaching user-code.

Jonas Maebe

2020-04-26 13:34

manager   ~0122443

It's indeed as nanobit explained.

Issue History

Date Modified Username Field Change
2020-04-26 04:32 Ian Hickson New Issue
2020-04-26 07:55 nanobit Note Added: 0122434
2020-04-26 08:06 nanobit Note Edited: 0122434 View Revisions
2020-04-26 13:34 Jonas Maebe Assigned To => Jonas Maebe
2020-04-26 13:34 Jonas Maebe Status new => resolved
2020-04-26 13:34 Jonas Maebe Resolution open => no change required
2020-04-26 13:34 Jonas Maebe FPCTarget => -
2020-04-26 13:34 Jonas Maebe Note Added: 0122443