[Issue 11132] New: Odd diagnostic with C-style struct initializer when union field is present

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 27 15:35:23 PDT 2013


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

           Summary: Odd diagnostic with C-style struct initializer when
                    union field is present
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-09-27 15:35:22 PDT ---
-----
struct S
{
    int x;
    union
    {
        int a;
        int b;
    }

    int z;
}

void main()
{
    S s = { 1, 2, 3 };
}
-----

$ dmd test.d
test.d(15): Error: variable test.main.s is not a static and cannot have static
initializer

A more appropriate diagnostic is emitted when using the regular D-style syntax:

S s = S(1, 2, 3);
test.d(17): Error: overlapping initialization for b

*However*, C (or is it just C++?) supports a special syntax for initializing
union fields:

S s = { 1, { 2 }, 3 };

But the above is an error in D:
test.d(17): Error: a struct is not a valid initializer for a int

I don't know if we want to support this. But we at least have to fix the
diagnostic in the first example.

-- 
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