Bug 7727 – "static initializer" for non-static unions too

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-18T06:00:00Z
Last change time
2013-10-05T00:33:52Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-03-18T06:00:53Z
struct Foo1 { ushort bar2; } struct Foo2 { union { ubyte[2] bar1; ushort bar2; } } void main() { immutable Foo1 foo1 = { bar2: 100 }; // OK immutable Foo2 foo2 = { bar2: 100 }; // error } DMD 2.059 gives: test.d(12): Error: variable test.main.foo2 is not a static and cannot have static initializer (Maybe it's just a well known problem of unions not supported in CTFE?)
Comment #1 by verylonglogin.reg — 2013-09-30T07:12:58Z
The issue has nothing to do with immutability: --- struct S { int i; double d; } union U { int i; double d; } void main() { S s = { d: 5 }; // OK U u = { d: 5 }; // Error: variable main.main.u is not a static and cannot have static initializer } --- By the way, docs don't mention one can do such "static initialization" for non-static structs or unions. Anyway, the difference should be obliterated by allowing/disallowing both.
Comment #2 by k.hara.pg — 2013-10-01T09:50:04Z
Comment #3 by bearophile_hugs — 2013-10-01T10:07:59Z
Changed issue title again.
Comment #4 by github-bugzilla — 2013-10-05T00:32:54Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8ee7e869b44f0cb4f72d6d0609cdbfa96caae002 fix Issue 7727 - "static initializer" for non-static unions too https://github.com/D-Programming-Language/dmd/commit/a35bd9efc2957eaa7ddea47b41d87c388bdde4b9 Merge pull request #2605 from 9rnsr/fix7727 Issue 7727 - "static initializer" for non-static unions too