www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11147] New: Nested structs in a union are not correctly initialized

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

           Summary: Nested structs in a union are not correctly
                    initialized
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: industry, spec
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrea.9940 gmail.com



DMD version: 2.063.2

The value of all variables in V should be zero, but the output shows they
aren't.

---------------
struct V {
    union {
        struct {
            float x = 1;
            float y = 1;
        float z = 1;
        }
        struct {
            float r;
            float g;
        float b;
        }
    }
}
import std.stdio;
void main() {
    writeln("V(", V.init.x, ", ", V.init.y, ", ", V.init.z, ", ", V.init.r, ",
", V.init.g, ", ", V.init.b, ")");
    writeln(V.init);
    writeln(V(V.init.x, V.init.y, V.init.z));
}
---------------

V(0, 0, 0, 0, 0, 0)
V(0, nan, nan, 0, nan, nan)
V(0, 0, 0, 0, 0, 0)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 30 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11147




 struct V {
     union {
         struct {
             float x = 1;
             float y = 1;
         float z = 1;
         }
         struct {
             float r;
             float g;
         float b;
         }
     }
 }
I posted the wrong code, the correct one is: struct V { union { struct { float x = 0; float y = 0; float z = 0; } struct { float r; float g; float b; } } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11147


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com



I wanted to add that this:

void main() {
  assert(V.init is V());
}

It would *appear* that the compiler is confused as to *what* the initial state
of V is.

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|spec                        |pull, wrong-code



https://github.com/D-Programming-Language/dmd/pull/2603

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




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a8d1d0911a10e2b941aba2a4de56c5a8b3f8dcea
fix Issue 11147 - Nested structs in a union are not correctly initialized

https://github.com/D-Programming-Language/dmd/commit/6e8d1f888c6d8e159e5145b5649252708976fb22


Issue 11147 - Nested structs in a union are not correctly initialized

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


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |FIXED


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