[Issue 20358] External initialization of private struct fields should be disallowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 6 11:07:44 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20358

--- Comment #3 from Max Samukha <maxsamukha at gmail.com> ---
(In reply to Simen Kjaeraas from comment #2)

> The solution here would be to define the default constructor as private when
> a struct has private members. 

That would be better, but simply making the default constructor private would
outlaw other valid use cases:

struct S {
   int x;
   private int y;
   int z;
}

// partial initialization should still be allowed
S s = {1};
S s2 = {1, z: 2}; // etc

In other words, private should be the respective parameters of the default
constructor.

--


More information about the Digitalmars-d-bugs mailing list