consider the code: void main () { import std.stdio; char ch = '!'; switch (ch) { int n = 42; case '!': writeln(n, ": wow!"); break; //(1) default: } } `n` variable is available at (1), but it is not initialized to 42, it contains random garbage instead. compiler should either execute all code before first `case` label unconditionally, or forbid having unlabeled code in `switch` block.
This is the underlying issue in bug 10524 and is closely related to issue 602.
https://github.com/dlang/dmd/pull/5869
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1a26535fd627ca398d2609228bce20905440360d fix Issue 14532 - switch block allows creating uninitialized variables https://github.com/dlang/dmd/commit/039853c2a752c9bc3bef770610ac04cadbdeb51f Merge pull request #5869 from WalterBright/fix14523 fix Issue 14532 - switch block allows creating uninitialized variables
*** Issue 10524 has been marked as a duplicate of this issue. ***
*** Issue 3820 has been marked as a duplicate of this issue. ***
*** Issue 16549 has been marked as a duplicate of this issue. ***
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/1a26535fd627ca398d2609228bce20905440360d fix Issue 14532 - switch block allows creating uninitialized variables https://github.com/dlang/dmd/commit/039853c2a752c9bc3bef770610ac04cadbdeb51f Merge pull request #5869 from WalterBright/fix14523
Commit pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/38c168303afcdf641877e31122106b2276ca642b Issue 14532 - switch block allows creating uninitialized variables