Null pointer dereferencing in D
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 14 07:51:08 PDT 2014
On Saturday, 14 June 2014 at 13:38:40 UTC, Maxim Fomin wrote:
>> Which is effectively a type system hole with @disable this :
>>
>> struct A { @disable this(); }
>> auto a = A.init;
>
> Why this is a type hole if initializer is explicitly provided?
>
> The idea of disabled this() is to prevent default
> initialization,
> not to reject potentially buggy one.
Well consider imaginary NotNullable struct that uses "@disable
this()" to guarantee that instance of that struct always has
meaningful state. By using (NotNullable!T).init you can get value
of that type which is in fact null and pass it as an argument to
function that expects NotNullable to always be non null. With no
casts involved you have just circumvented guarantees static type
system was suppose to give.
More information about the Digitalmars-d
mailing list