Bug 13495 – DMD fails to call struct constructor with default args when default constructor is @disabled
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-18T19:50:44Z
Last change time
2018-04-05T12:56:44Z
Assigned to
No Owner
Creator
Ketmar Dark
Comments
Comment #0 by ketmar — 2014-09-18T19:50:44Z
i think that calling struct constructor with omited default parameters should be allowed even if struct has @disable this(). i.e. the following code should work:
struct S {
int v;
@disable this ();
this (int n=42) { v = n; }
}
void main () {
auto s = S();
}
now compiler complains: "Error: constructor z03.S.this is not callable because it is annotated with @disable". but here is another constructor that perfectly fits.
Comment #1 by hsteoh — 2014-09-18T19:55:58Z
I think this is a bug, not just an enhancement request.
Comment #2 by razvan.nitu1305 — 2018-04-05T12:56:44Z
The code in the OP now issues a deprecation : Deprecation: constructor `test.S.this` all parameters have default arguments, but structs cannot have default constructors. PR : https://github.com/dlang/dmd/pull/5331
Default construction is disabled, so this case is no longer actual. Closing as fixed.