Bug 8703 – Disabling default ctor does not forbid default construction

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-21T05:49:00Z
Last change time
2012-09-21T18:57:04Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2012-09-21T05:49:56Z
This code should fail to compile, but doesn't. struct S { @disable this(); } void main() { auto s = S(); }
Comment #1 by simen.kjaras — 2012-09-21T06:06:56Z
*** This issue has been marked as a duplicate of issue 7021 ***
Comment #2 by maxim — 2012-09-21T09:05:26Z
(In reply to comment #0) > This code should fail to compile, but doesn't. > > struct S > { > @disable this(); > } > void main() > { > auto s = S(); > } Actually it is consistent with current D implementation (whether you like it or not). The root of this issue is that S() is neither "implicit constructor" nor struct literal - it is default initializer for struct. Currently structs can be initialized at runtime by four methods: default initializer, struct literal, constructor or opCall. In the example you block ctor but not default initializer. This is why S() works, but S.__ctor() as expected doesn't.
Comment #3 by k.hara.pg — 2012-09-21T18:57:04Z
(In reply to comment #2) > (In reply to comment #0) > > This code should fail to compile, but doesn't. > > > > struct S > > { > > @disable this(); > > } > > void main() > > { > > auto s = S(); > > } > > Actually it is consistent with current D implementation (whether you like it or > not). The root of this issue is that S() is neither "implicit constructor" nor > struct literal - it is default initializer for struct. Currently structs can be > initialized at runtime by four methods: default initializer, struct literal, > constructor or opCall. In the example you block ctor but not default > initializer. This is why S() works, but S.__ctor() as expected doesn't. Yes, that's my point. In current S() represents default initializer, but I think it is invalid, because S has a constructor efen if it has no parameter and @disable.