Bug 12945 – Deprecation for legacy static opCall feature in initializing
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-19T05:40:21Z
Last change time
2022-08-25T11:03:35Z
Assigned to
No Owner
Creator
Kenji Hara
Comments
Comment #0 by k.hara.pg — 2014-06-19T05:40:21Z
It is an old feature to emulate constructor call from D1 age.
struct S {
int num;
static S opCall(int n) {
S s;
s.num = n;
return s;
}
}
void main() {
S s = 1;
// This line is translated to:
// S s = S.opCall(1);
}
But in D2, "implicit constructor call" feature properly supports such the initializing syntax.
struct S {
int num;
this(int n) {
this.num = n;
}
}
void main() {
S s = 1;
// This line is translated to:
// S s = S(1);
}
Therefore, we can deprecate/remove the problematic opCall feature in initializing.
Comment #1 by issues.dlang — 2014-06-19T05:55:32Z
static opCall without any parameters should continue work though, since you can't declare a default constructor.
Comment #2 by k.hara.pg — 2014-06-19T06:29:29Z
(In reply to Jonathan M Davis from comment #1)
> static opCall without any parameters should continue work though, since you
> can't declare a default constructor.
This proposal does not change it.
Comment #3 by razvan.nitu1305 — 2022-08-25T11:03:35Z
I don't see why this shouldn't work in the absence of a constructor in S. Currently, constructor is preferred if both constructor and opCall are defined.
Closing this as WONTFIX.