[Issue 8902] Unexpected "duplicate union initialization for X" error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 28 01:06:46 PDT 2012


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


monarchdodra at gmail.com changed:

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


--- Comment #1 from monarchdodra at 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: -------


More information about the Digitalmars-d-bugs mailing list