Example program: --- struct S { this(ref inout(S) other) inout {} } union U { S s; } static assert(!__traits(compiles, (U original) { U copy = original; } )); --- The language spec says: > If a union S has fields that define a copy constructor, whenever an object of > type S is initialized by copy, an error will be issued. The same rule applies > to overlapped fields (anonymous unions). According to this paragraph, the static assert above should pass. However, as of DMD 2.093.1, it fails.
@pbackus created dlang/dmd pull request #11634 "Fix issue 21198 - Inout copy constructor on union field does not prev…" fixing this issue: - Fix issue 21198 - Inout copy constructor on union field does not prevent copy-initialization of union Previously, generated copy constructors of unions were disabled only if they failed to type-check. They are now disabled in all cases, as required by the language spec. https://github.com/dlang/dmd/pull/11634
dlang/dmd pull request #11634 "Fix issue 21198 - Inout copy constructor on union field does not prev…" was merged into stable: - 573bf6a171f5dd23caebda7bb2ca66455c3d6d0f by Paul Backus: Fix issue 21198 - Inout copy constructor on union field does not prevent copy-initialization of union Previously, generated copy constructors of unions were disabled only if they failed to type-check. They are now disabled in all cases, as required by the language spec. https://github.com/dlang/dmd/pull/11634
dlang/dmd pull request #11718 "merge stable" was merged into master: - f602545af9c0db08b70a8ff2372515416c1a2d2a by Paul Backus: Fix issue 21198 - Inout copy constructor on union field does not prevent copy-initialization of union Previously, generated copy constructors of unions were disabled only if they failed to type-check. They are now disabled in all cases, as required by the language spec. https://github.com/dlang/dmd/pull/11718