www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8902] New: Unexpected "duplicate union initialization for X" error

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902

           Summary: Unexpected "duplicate union initialization for X"
                    error
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-10-28
10:12:15 MSK ---
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...
}
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 28 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com
           Severity|normal                      |major


--- Comment #1 from monarchdodra gmail.com 2012-10-28 01:06:44 PDT ---
(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... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902



--- Comment #2 from Denis Shelomovskij <verylonglogin.reg gmail.com> 2012-10-28
12:12:11 MSK ---
(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)) { } --- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902



--- Comment #3 from github-bugzilla puremagic.com 2012-12-12 07:41:20 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/44310012fea6751561a852cc5ef4056a0ba9d272
Add note about Issue 8902 workaround

* Issue 8902 URL: http://d.puremagic.com/issues/show_bug.cgi?id=8902

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902



--- Comment #4 from github-bugzilla puremagic.com 2012-12-13 04:57:44 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902



--- Comment #5 from github-bugzilla puremagic.com 2013-03-05 08:23:20 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8902


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 05 2013