Bug 20575 – Strange behaviour of version'ed switch cases

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-11T19:28:16Z
Last change time
2024-12-13T19:07:05Z
Assigned to
No Owner
Creator
moonlightsentinel
Moved to GitHub: dmd#17938 →

Comments

Comment #0 by moonlightsentinel — 2020-02-11T19:28:16Z
Consider the following example: void main() { import std.stdio; foreach (i; 1 .. 4) { write(i, ": "); switch (i) { version (A) case 1: version (B) case 2: write("Case"); break; case 3: default: write("Default"); } writeln(); } } Executing this example with different versions yields strange results: [ ]: // OK 1: Default 2: Default 3: Default [A]: // Strange 1: 2: Default 3: Default [B]: // Maybe? 1: Default 2: Default 3: Default [A, B]: // OK 1: Case 2: Case 3: Default [B] suggests that the missing A discards both case statements (which form a CaseRangeStatement) and hence executes the default. But [A] seems to discard "case 2: writeln(...);" without implicit fallthough / compiler warning.
Comment #1 by robert.schadek — 2024-12-13T19:07:05Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17938 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB