Bug 19321 – Unions "may not" have fields with destructors

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-10-20T16:34:47Z
Last change time
2018-11-22T17:06:54Z
Assigned to
No Owner
Creator
Stanislav Blinov

Comments

Comment #0 by stanislav.blinov — 2018-10-20T16:34:47Z
The spec (https://dlang.org/spec/struct.html#struct-destructor) says: "2. Unions may not have fields that have destructors." That's not true anymore, e.g. see https://issues.dlang.org/show_bug.cgi?id=16104 https://github.com/dlang/dmd/pull/5830 Perhaps, a better way to describe this in the spec is in order? E.g.: "2. Destructors are not automatically called for union fields. If destruction is desired, it must be explicit. For example, by adding a call `u.field.__xdtor`." Or just excise that entry altogether?
Comment #1 by simen.kjaras — 2018-10-21T09:18:29Z
Definitely not excised - the fact that union member destructors should not be called by the compiler is not immediately obvious, and the user should be warned of this fact. Also, the text should probably advocate destroy(u.field) over calling __xdtor directly. Otherwise, your text looks good. One related problem is issue 19122, or the fact that destructors are indeed being called automatically for union members. That shouldn't affect this issue, but it means that your text isn't correct until 19122 is fixed.
Comment #2 by stanislav.blinov — 2018-10-21T11:09:08Z
I propose to still make the change, but also add a note about outstanding bugs (IIRC there was another one concerning assignment of fields). At least that way the spec will not be misleading.
Comment #3 by github-bugzilla — 2018-11-22T17:06:53Z
Commit pushed to master at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/83a1aa6cee332986fe7eeb8142f965b09a216cce Merge pull request #2515 from radcapricorn/fix19321 Fix issue 19321 merged-on-behalf-of: Jacob Carlborg <[email protected]>