Bug 14532 – switch block allows creating uninitialized variables

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-30T08:39:00Z
Last change time
2017-08-02T08:07:18Z
Keywords
accepts-invalid, pull, safe
Assigned to
nobody
Creator
ketmar
Blocks
10524
See also
https://issues.dlang.org/show_bug.cgi?id=10524, https://issues.dlang.org/show_bug.cgi?id=602, https://issues.dlang.org/show_bug.cgi?id=6095

Comments

Comment #0 by ketmar — 2015-04-30T08:39:52Z
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.
Comment #1 by yebblies — 2015-04-30T13:02:47Z
This is the underlying issue in bug 10524 and is closely related to issue 602.
Comment #2 by bugzilla — 2016-06-15T18:14:37Z
Comment #3 by github-bugzilla — 2016-06-17T01:37:16Z
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
Comment #4 by bugzilla — 2016-06-18T21:03:55Z
*** Issue 10524 has been marked as a duplicate of this issue. ***
Comment #5 by mk — 2016-09-18T14:00:29Z
*** Issue 3820 has been marked as a duplicate of this issue. ***
Comment #6 by mathias.lang — 2016-09-27T15:32:10Z
*** Issue 16549 has been marked as a duplicate of this issue. ***
Comment #7 by github-bugzilla — 2016-10-01T11:47:50Z
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
Comment #8 by github-bugzilla — 2017-08-02T08:07:18Z
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