[Issue 2485] New: non-static initialization of struct using static initializer syntax generates wrong code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 2 09:42:01 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2485
Summary: non-static initialization of struct using static
initializer syntax generates wrong code
Product: D
Version: 1.035
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: tomas at famolsen.dk
The example from the spec added to document that static struct initializer
syntax is allowed for non-static initialization doesn't do what it's supposed
to with DMD.
I've produced a test case from it:
struct S {
int a; int b; int c; int d = 7;
}
void test(int i) {
S s = { 1, i }; // q.a = 1, q.b = i, q.c = 0, q.d = 7
assert(s.a == 1);
assert(s.b == i);
assert(s.c == 0); // line 8
assert(s.d == 7);
}
void main() {
test(42);
}
$ dmd foo.d
$ ./foo
Error: AssertError Failure foo.d(8)
--
More information about the Digitalmars-d-bugs
mailing list