Le 27/11/2011 22:24, Simen Kjærås a écrit :
On Sun, 27 Nov 2011 21:19:38 +0100, deadalnix <[email protected]> wrote:In addition, here is a workaround : // Wonderfull ! @disable this(); // Default constructor workaround. this(int dummy = 0) { ... } But that look very dirty and it feels like working against the language.I believe your "workaround" will disappoint you, as it simply does not run. import std.stdio; struct A { int value; @disable this(); this(int dummy = 0) { value = 3; writeln("Hello from struct default constructor!"); // Never happens. } } void main() { A a = A(); writeln( a.value ); // Writes 0 } More importantly, this shows a bug in DMD - namely that structs with @disabled default constructors can be created without a call to any constructor and with no error message. In fact, if one removes the constructor with dummy arguments, the program still compiles. http://d.puremagic.com/issues/show_bug.cgi?id=7021
So that is even worse that what I though. This struct situation is very messy and inconsistent. We should definie what we want for that and have a descent spec.
I just found something new : if you disable this(this), then opAssign should be allowed (it is allowed, according to the website, when implicit cast doesn't exists). The copy don't work with opAssign and disabled postblit . . .
