I think it would really suck to introduce special cases to forbid default initialization of structs. And assuming T was the type of the struct, what would T.init do? Or typeid(T).init()?

Use a class instead.

If you really need a struct, you could use a private field, that signals if the struct was properly initialized.

E.g.

struct Foo {
        debug private bool initialized;
        
        static Foo opCall() {
                Foo n;
                debug n.initialized = true;
                return n;
        }
        
        void foo() {
                assert (initialized);
                //do something useful
        }
}

Reply via email to