Adding 'static' before Degree a eliminates the error. A reduced test case that shows the same behavior:
struct Ranged {
float value, min, max, range;
}
void main() {
Ranged a = {0f, 0f, 360f, 360f};
}
Changing the line in main to "static Ranged ..." also removes the error. Is the original test case actually valid code? Struct initializers, by spec, are only allowed for static instances. The syntax for default initialization for structs is like this:
struct X { int a; int b; int c; int d = 7; }
I'm not sure that it's possible to give struct's new default initializations when typedef'ing them like this. Walter? Language lawyer? For reference, the typedef part of the spec is fairly anemic and only gives this one example:
typedef int myint = 7;
myint m; // initialized to 7
Comment #3 by braddr — 2006-10-16T05:52:58Z
With dmd 167 it reported this:
378-a.d(8): variable foo.main.a is not a static and cannot have static initializer
If I had to guess, I'd say the problem is related to the stack variable initialization changes in 168.
Comment #4 by h3r3tic — 2006-10-16T07:41:58Z
You're probably right... Too bad, as default initialization for non-static struct instances or struct ctors would be very handy. Sorry for the misinformation.
I guess I'll let the bug stay because of the assertion...
Comment #5 by braddr — 2006-10-24T14:10:17Z
*** Bug 452 has been marked as a duplicate of this bug. ***