digitalmars.D.bugs - [Issue 14532] New: switch block allows creating uninitialized
- via Digitalmars-d-bugs (28/28) Apr 30 2015 https://issues.dlang.org/show_bug.cgi?id=14532
https://issues.dlang.org/show_bug.cgi?id=14532 Issue ID: 14532 Summary: switch block allows creating uninitialized variables Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: ketmar ketmar.no-ip.org 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. --
Apr 30 2015