Bug 20842 – Structs with disabled default/copy ctors can't be initialized

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-05-18T17:52:07Z
Last change time
2020-05-20T00:27:16Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus

Comments

Comment #0 by snarwin+bugzilla — 2020-05-18T17:52:07Z
The following program fails to compile with DMD v2.092.0: --- struct A { int i; @disable this(ref A); } A a = { i: 123 }; struct B { int i; @disable this(); } B b = { i: 123 }; --- The compiler gives the following output: --- onlineapp.d(7): Error: struct `A` has constructors, cannot use `{ initializers }`, use `A( initializers )` instead onlineapp.d(15): Error: struct `B` has constructors, cannot use `{ initializers }`, use `B( initializers )` instead --- The expected behavior is for @disabled copy and default constructors to forbid only copy initialization and default initialization, respectively, rather than forbidding all initialization.
Comment #1 by dlang-bot — 2020-05-18T21:41:34Z
@pbackus created dlang/dmd pull request #11159 "Fix Issue 20842 - Structs with disabled default/copy ctors can't be i…" fixing this issue: - Fix Issue 20842 - Structs with disabled default/copy ctors can't be initialized A struct must now have at least one non-@disabled constructor to be ineligible for brace initialization. https://github.com/dlang/dmd/pull/11159
Comment #2 by dlang-bot — 2020-05-20T00:27:16Z
dlang/dmd pull request #11159 "Fix Issue 20842 - Structs with disabled default/copy ctors can't be i…" was merged into master: - a42031736ce1f6294da682bac54082abf7e24401 by Paul Backus: Fix Issue 20842 - Structs with disabled default/copy ctors can't be initialized A struct must now have at least one non-@disabled constructor to be ineligible for brace initialization. https://github.com/dlang/dmd/pull/11159