T.init and @disable this

deadalnix deadalnix at gmail.com
Thu Oct 4 19:09:41 PDT 2012


Le 04/10/2012 10:18, monarch_dodra a écrit :
> I'm trying to find out the exact semantics of
>
> @disable this();
>
> It is not well documented, and the fact that it is (supposedly) buggy
> makes it really confusing.
>
> My understanding is that it "merely" makes it illegal to default
> initialization your type: You, the developer, have to specify the
> initial value.
>
> //----
> T t; //initializer required for type
> //----
> Which means, you, the developper, must explicitly choose an initial value.
>
> However, DOES or DOES NOT this remain legal?
> //----
> T t = T.init; //Fine: You chose the initializer T.init
> //----
>
> Keep in mind it is not possible to make "T.init" itself disappear,
> because nothing can be constructed if T.init is not first memcopied onto
> the object, before calling any constructor proper.
>
> I think this should be legal, because you, the developer, is asking for
> it, just the same way one can write "T t = void".
>
> Making it illegal would pretty much make T unmoveable, un-emplaceable,
> un-initializeable on un-initialized memmory, and would probably break
> more than one function/trait which uses "T.init"
>
> Feedback?

Making T.init unsafe in this case should be enough.


More information about the Digitalmars-d mailing list