Summary: { } struct literals not documented, and not working
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD

--- Comment #0 from Austin Hastings <> 2010-10-01 06:24:48 
PDT ---
I unthinkingly created a struct literal like S s = { 9 }; and it worked (which,
now that I'm complaining about it, I can't find documented in the chm). 

But this format doesn't appear to initialize any other fields:
$ cat test.d
import std.stdio;

struct S {
    int key;

    int x = 1;

    void dump() {
        writefln("%s %s", key, x);

void main() {
    S s1;

    S s2 = { 9 };
This code prints:
$ dmd -run test.d
0 1
9 1310436

Note the trash in the second variable. I am not sure what the correct solution
is - should struct literals require ctor style, or use static-initializer
format and an implicit copy? - but I would certainly have appreciated a
warning, if nothing else, when I started compiling code like this.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to