Bug 8902 – Unexpected "duplicate union initialization for X" error

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-28T00:12:00Z
Last change time
2013-03-05T08:32:12Z
Keywords
rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2012-10-28T00:12:15Z
Should assigning `.init` to a union be allowed or disallowed? At leas current behavior is inconsistent: --- union U { int a, b; } enum U u0 = U.init; // No errors U u1; // No errors U u2 = U.init; // Error: duplicate union initialization for b void main() { U u3 = U.init; // No errors immutable U u4 = U.init; // No errors immutable static U u5 = U.init; // Error: duplicate union... static U u6 = u4; // Error: duplicate union... static U u7 = U.init; // Error: duplicate union... } ---
Comment #1 by monarchdodra — 2012-10-28T01:06:44Z
(In reply to comment #0) > Should assigning `.init` to a union be allowed or disallowed? At leas current > behavior is inconsistent: > > --- > union U { int a, b; } > > enum U u0 = U.init; // No errors > U u1; // No errors > U u2 = U.init; // Error: duplicate union initialization for b > > void main() > { > U u3 = U.init; // No errors > immutable U u4 = U.init; // No errors > immutable static U u5 = U.init; // Error: duplicate union... > static U u6 = u4; // Error: duplicate union... > static U u7 = U.init; // Error: duplicate union... > } > --- It would further more appear that the compiler has trouble detecting this in conditional implementations, which makes it difficult to bypass this problem. //---- import std.stdio; union U { int a, b; } void main() { static if (is(typeof((inout int _dummy=0){static U i = U.init;}))) //FINE { static U i = U.init; //L9: DERP } } //---- main.d(9): Error: duplicate union initialization for b //---- Raising priority due to the impossibility to easily bypass this problem...
Comment #2 by verylonglogin.reg — 2012-10-28T02:12:11Z
(In reply to comment #1) > (In reply to comment #0) > It would further more appear that the compiler has trouble detecting this in > conditional implementations, which makes it difficult to bypass this problem. Possible this is related to an error gagging problem. E.g. consider this: --- union U { int a, b; } template t(T) { static T t = T.init; } // Error: duplicate union initialization for b static if (__traits(compiles, t!U)) { } ---
Comment #3 by github-bugzilla — 2012-12-12T07:41:20Z
Comment #4 by github-bugzilla — 2012-12-13T04:57:44Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/1c54f33603b00163c4736696f2e24587e024327d fixup for Issue 8902 After default initialization, only the first one in overlapped fields is readable in CTFE. https://github.com/D-Programming-Language/phobos/commit/437f15689dae803510321185f3545479dee7c473 Merge pull request #1007 from 9rnsr/fix8902 fixup for Issue 8902
Comment #5 by github-bugzilla — 2013-03-05T08:23:20Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/840d88a6e539e9817cffdc4abe8ad6357897d54a fix Issue 8902 - Unexpected "duplicate union initialization for X" error https://github.com/D-Programming-Language/dmd/commit/a975ed6aacd7e2604808a74fb509da99c10624ef Merge pull request #1369 from 9rnsr/fix8902 Issue 8902 - Unexpected "duplicate union initialization for X" error