[Issue 7021] Structs with disabled default constructors can be constructed without calling a constructor.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Sep 21 12:18:28 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7021
--- Comment #10 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-09-21 12:19:15 PDT ---
It was my understanding that
@disable this();
was specifically the syntax to disable the init property. Certainly, trying to
disable init directly doesn't work as far as I can tell. And since structs
don't _have_ default constructors, I don't know what else
@disable this();
would be disabling (other than perhaps S(), which uses the init property
anyway, since there's no default consturctor).
The whole point is to be able disable init so that you can _never_ use it for
_anything_. You must _always_ directly initialize such a type (unless you
directly initialize it with void).
Yes, normally, T.init is the value that the type has before any constructor is
called, but if it's disabled, then it effectively does not exist, and it should
be impossible to use T.init _anywhere_. Construction should work the same with
any constructors that do exist (so the object state prior to construction is
the same as what T.init would have been had it existed), but it should be
impossible to default initialize such a type or to use it in any context which
would require default initialization, and it should be impossible to reference
that type's init in code anywhere. That's the whole point of disabling init,
and
@disable this();
is specifically for disabling init. It doesn't affect declared constructors
work, but it affects every other aspect of init.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list