Test case:
```
enum E : ubyte
{
e0,
e1
}
void oops(E e)
{
switch (e)
{
case 300: break; // accepted but can be statically verified to be wrong
default:
}
}
void main()
{
}
```
there are two things here
1. even without E body, we know that 300 is out of range
2. with the body we can check that 300 is not 0 either 1.
But for now the compiler is just happy with that code.
Likely a problem of premature integral promotion.
This can cause problems when the definition of E is updated.
Comment #1 by qs.il.paperinik — 2024-07-25T20:47:21Z
This is actually 2 issues:
- If a `case` label is out of range for the `enum` type’s backing type, should that be illegal? (IMO, yes, except in templates.)
- If a `case` label has a value that’s in range for the type’s backing type, but is different from all `enum` values, should that be an error? (IMO, hard no. Some `enum` types are bit-fields and it can make sense to test for certain combinations specifically.)
Comment #2 by robert.schadek — 2024-12-13T19:32:38Z