Class/struct invariants

Steven Schveighoffer schveiguy at
Wed Jun 16 08:16:22 PDT 2010

On Wed, 16 Jun 2010 10:58:28 -0400, Simen kjaeraas  
<simen.kjaras at> wrote:

> Steven Schveighoffer <schveiguy at> wrote:
>> During default struct construction, no constructors are run (they  
>> aren't allowed anyways) and no invariants are run.  What would be the  
>> point of running an invariant during default construction?  The only  
>> think it could possibly do is make code like this:
>> S s;
>> Fail without -release, and pass with -release.  I don't see the value  
>> in that.
> Ah, but I do. If it is an error to create an uninitialized struct of
> type S, then the above code is a bug, is it not?

Yes, but an invariant doesn't guarantee that, since it is non-existent in  
release mode, and a compile time error is better.

What you want is to be able to disable the default constructor.  Andrei  
has hinted it might be a future improvement on other threads.


More information about the Digitalmars-d-learn mailing list