www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1432] New: Bogus "overlapping initialization" error with structs, unions, and member initializers

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

           Summary: Bogus "overlapping initialization" error with structs,
                    unions, and member initializers
           Product: D
           Version: 1.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jarrett.billingsley gmail.com


struct S
{
        int blah = 5;

        union
        {
                int x;
                T t;
                Object o;
        }
}

struct T
{
        int y;
}

Gives the error "dtest.d(26): struct dtest.S overlapping initialization for
struct S.blah"

If you remove the initializer for S.blah, or if you remove the t member from
that union, or if you make the union named, it works.


-- 
Aug 19 2007
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1432





------- Comment #1 from tomas famolsen.dk  2009-04-22 21:33 -------
Another variation:

union S
{
    float[2] a;
    struct
    {
        union { float i = 1; float x; }
        union { float j = 2; float y; }
    }
}

$ dmd bar.d -c
bar.d(2): Error: union bar.S overlapping initialization for struct S.i
bar.d(2): Error: union bar.S overlapping initialization for struct S.j

If 'a' is moved below the anonymous struct it works. The spec does not mention
this special case as far as I can tell. Explicit initialization of aggregate
fields inside anonymous struct/union combinations should be documented.


-- 
Apr 22 2009