Bug 24341 – Switch over enum are poorly verified

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-01-15T23:36:57Z
Last change time
2024-12-13T19:32:38Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: dmd#20384 →

Comments

Comment #0 by b2.temp — 2024-01-15T23:36:57Z
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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20384 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB