Bug 10186 – default construction is disabled even if default ctor declared

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-27T14:13:55Z
Last change time
2023-02-27T14:47:33Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Henning Pohl

Comments

Comment #0 by henning — 2013-05-27T14:13:55Z
struct S { @disable this(); this(int i) { } } class C { this() { s = S(1); } S s; } void main() { auto c = new C; } ----- main.d(17): Error: default construction is disabled for type C -----
Comment #1 by henning — 2013-05-27T14:16:55Z
Comment #2 by github-bugzilla — 2013-05-27T15:25:47Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4c138e35e8fab9b5d035ba385d0ba54dc2b7124e fix issue 10186 - default construction is disabled even if default ctor declared https://github.com/D-Programming-Language/dmd/commit/81b5d0999b1679b0c37c285acc4ddf9b6f70bc4f Merge pull request #2087 from hpohl/10186 fix issue 10186 - default construction is disabled even if default ctor declared
Comment #3 by k.hara.pg — 2013-05-27T15:44:56Z
(In reply to comment #1) > https://github.com/D-Programming-Language/dmd/pull/2087 The fix is incomplete. struct S { @disable this(); this(int i) {} } class C { S s; // move definition before the ctor this() { s = S(1); } } void main() { auto c = new C; // line 16 } test.d(16): Error: default construction is disabled for type C
Comment #4 by github-bugzilla — 2013-06-01T13:53:10Z
Comment #5 by verylonglogin.reg — 2013-06-02T23:18:19Z
What about `this(int = 0)` class constructor?
Comment #6 by samukha — 2013-10-08T10:59:20Z
And, with v2.064-devel-64d739f, C.s is still assigned from a temporary object instead of being constructed directly. That defeats the purpose of "@disable this", because assignment assumes that the target object has been properly constructed. And, in the presence of "@disable this", "set to init" does not qualify for "properly constructed".
Comment #7 by k.hara.pg — 2013-10-11T07:06:48Z
(In reply to comment #5) > What about `this(int = 0)` class constructor? https://github.com/D-Programming-Language/dmd/pull/2655
Comment #8 by k.hara.pg — 2013-10-11T07:08:46Z
(In reply to comment #6) > And, with v2.064-devel-64d739f, C.s is still assigned from a temporary object > instead of being constructed directly. That defeats the purpose of "@disable > this", because assignment assumes that the target object has been properly > constructed. And, in the presence of "@disable this", "set to init" does not > qualify for "properly constructed". The issue has been already filed in bug 9665.
Comment #9 by k.hara.pg — 2013-11-28T21:07:21Z
*** Issue 7121 has been marked as a duplicate of this issue. ***
Comment #10 by verylonglogin.reg — 2015-01-07T14:07:23Z
Also one even can't create an array of class refereces: --- struct S { @disable this(); this(int i) {} } class C { S s; this() { s = S(1); } } void main() { auto c = new C[1]; // line 15 } --- main.d(15): Error: default construction is disabled for type main.C --- Note: This case is easily workaroundable e.g. setting `length` property.
Comment #11 by razvan.nitu1305 — 2023-02-27T14:47:33Z
I cannot reproduce the first incarnations of this bug [1][2]. As for the 3rd provided test case [3], the sample is indeed invalid because the array of classes needs to enclose the the init value of the structs in the array elements, thus violating the @disable this() of struct S. As such, this bug has been fixed. [1] https://issues.dlang.org/show_bug.cgi?id=10186#c0 [2] https://issues.dlang.org/show_bug.cgi?id=10186#c3 [3] https://issues.dlang.org/show_bug.cgi?id=10186#c10