Error in spec: struct init with member names

Johan Engelen via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 3 11:14:43 PDT 2017


The spec (or DMD frontend) is broken regarding struct 
initialization with explicit mention of member field names:
https://dlang.org/spec/struct.html#static_struct_init

The spec says:
"The static initializer syntax can also be used to initialize 
non-static variables, provided that the member names are not 
given."

But this code compiles correctly:
```
struct S { int a; int b; int c; int d = 7;}
void test(int i)
{
     S q = {a : 1, c : i }; // q.a = 1, q.b = 0, q.c = i, q.d = 7
}
```

I haven't come up with a reason for why it would not be allowed 
to use member names, so I think it is an error in the spec. If 
not, please explain. If yes, please fix the spec.

Thanks!
   Johan



More information about the Digitalmars-d mailing list