Bug 12764 – Disabled struct default construction circumvented when field is written to
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-18T15:44:40Z
Last change time
2018-05-26T13:05:38Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Andrej Mitrovic
Comments
Comment #0 by andrej.mitrovich — 2014-05-18T15:44:40Z
-----
struct S
{
@disable this();
this(string) { }
int f;
}
class C
{
this(int)
{
s.f = 1; // circumvents default ctor!
}
S s;
}
void main() { }
-----
If we comment out writing to 'f' we get:
test.d(11): Error: constructor test.C.this field s must be initialized in constructor
This should always be emitted unless we explicitly call "s = S(...)" or "s = S.init".
Comment #1 by razvan.nitu1305 — 2018-04-22T11:44:55Z