const struct not accepted as initializer by dmd 2.00x
torhu
fake at address.dude
Thu Jul 12 08:42:25 PDT 2007
This code compiles fine with dmd 1.017, but not with dmd 2.002.
---
struct Inner
{
int value;
}
struct Outer {
//const(Inner) i; // this fixes it, but is not valid in D 1.0
Inner i;
}
const Inner ic = { 5 }; // const or invariant here makes no difference
Outer outer = {
i: ic // line 14
//i: { 5 } // this is allowed
};
---
c:\prog\test\D>dmd -c test
test.d(14): Error: non-constant expression cast(Inner)ic
---
I'm wondering why 'const Inner ic = { 5 };' isn't considered const
enough to be accepted as an initializer for outer.ic. I'm trying to
make this code work in D version 1 too, and since it's for an example,
I'd like avoid any string mixins or other ugly workarounds.
More information about the Digitalmars-d-learn
mailing list