D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21198 - Inout copy constructor on union field does not prevent copy-initialization of union
Summary: Inout copy constructor on union field does not prevent copy-initialization of...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-08-25 16:26 UTC by Paul Backus
Modified: 2020-09-11 06:12 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Paul Backus 2020-08-25 16:26:35 UTC
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.
Comment 1 Dlang Bot 2020-08-27 23:14:49 UTC
@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
Comment 2 Dlang Bot 2020-08-29 18:49:32 UTC
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
Comment 3 Dlang Bot 2020-09-11 06:12:25 UTC
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