[Issue 16549] New: Switch statement can skip initialization
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Sep 26 23:44:29 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16549
Issue ID: 16549
Summary: Switch statement can skip initialization
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: doob at me.com
Compiling and running the following code will trigger the assertion since "foo"
is not initialized:
struct State
{
int jumpLabel;
}
void bar(State s)
{
switch(s.jumpLabel)
{
int foo;
case 0:
assert(foo == foo.init);
default:
break;
}
}
void main()
{
bar(State(0));
}
It seems like it's the struct that is fooling the compiler. If it's replaced
with a plain int, "foo" will be initialized.
--
More information about the Digitalmars-d-bugs
mailing list