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

--- Comment #7 from Max Samukha <[email protected]> ---
(In reply to Simen Kjaeraas from comment #6)
> In favor of closing as invalid: If your type has an invariant that requires
> private fields to have specific values, you should define a constructor that
> establishes said invariant. If you don't, you've essentially told the world
> you'll accept any and all values.

But there is also lazy initialization:

// invariant is x == 1.
// neither disabled default ctor nor non-default ctors are wanted
struct S {
    private int x;
    void foo() {
        if (x == 0) x = 1;
    }
}

auto s = S(2); // problem

I agree that the issue is probably minor, because most structs with private
fields will have at least one constructor defined or disabled anyway. I
disagree that the issue is invalid.

--

Reply via email to