digitalmars.D.learn - const struct not accepted as initializer by dmd 2.00x
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.
Jul 12 2007
torhu wrote: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.I guess the real question is: is it a bug that ic isn't accepted as an initializer?
Jul 12 2007