Comment #0 by bearophile_hugs — 2010-02-18T11:04:44Z
void main() {
switch (1) {
int x;
case 1:
assert(x == int.init);
default:
}
}
Here often x != x.init.
D isn't C, so it's better to avoid holes in its semantics, if possible.
Comment #2 by bearophile_hugs — 2011-05-12T15:33:44Z
*** Issue 5989 has been marked as a duplicate of this issue. ***
Comment #3 by bearophile_hugs — 2012-03-11T14:14:59Z
A probably related case:
import std.stdio;
enum Foo { A }
void main() {
Foo f = Foo.A;
switch (f) {
writeln(f);
case Foo.A: break;
}
}
With DMD 2.059head it prints nothing.
Comment #4 by code — 2012-03-12T07:24:29Z
*** Issue 7630 has been marked as a duplicate of this issue. ***
Comment #5 by code — 2012-03-12T07:37:28Z
You can only execute that block with a goto or a loop.
The initialization should happen anyhow.
Comment #6 by maxim — 2013-05-19T21:09:14Z
*** Issue 10121 has been marked as a duplicate of this issue. ***
Comment #7 by code — 2013-05-20T03:20:58Z
IIRC this switch is implemented as below. Unless we expect the block to always run, as in comment 3, it's difficult to fix.
int foo(int a)
{
switch (var)
{
int res;
case 1: res = 1; return res;
default: return res;
}
}
int foo(int a)
{
if (var == 1) goto L1;
else goto Ldefault;
int res;
L1: res = 1; return res;
Ldefault: return res;
}
Comment #8 by mk — 2016-09-18T14:00:29Z
*** This issue has been marked as a duplicate of issue 14532 ***