Bug 3271 – Struct initializers silently fail

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-08-29T08:45:00Z
Last change time
2015-06-09T01:28:07Z
Keywords
wrong-code
Assigned to
nobody
Creator
nfxjfg

Comments

Comment #0 by nfxjfg — 2009-08-29T08:45:36Z
The following example seems to show, that dmd 2.031 generates invalid code for struct initializers. Test.X contains an empty string instead of "4", and the assertion fails. Amusingly, when using opCall and CTFE instead, it seems to work (version BUG disabled). PS: the unreduced version of this code also failed under dmd 1.0xx (don't know which version exactly). But this reduced example seems to work under dmd 1.046. Code: version = BUG; struct Test { version (BUG) { static enum Test X = {value:"4"}; } else { static enum Test X = Test("4"); } string value = ""; } void main() { Test x; assert(x.X.value == "4"); }
Comment #1 by bugzilla — 2011-04-04T16:30:18Z