Skip to content

CWG2897 [class.copy.ctor, class.copy.assign] Copying object representation may be problematic for potentially-overlapping union subobjects #542

@frederick-vs-ja

Description

@frederick-vs-ja

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [class.copy.ctor], [class.copy.assign]

Link to reflector thread (if any):

Issue description:

It's specified in [class.copy.ctor] p15 and [class.copy.assign] p13 that a trivial and elegible copy or move function of a union copies the object representation, which can be problematic when the union object is a potentially-overlapping member subobject, and another subobject of the complete object overlaps with its tail padding, because the latter will be unintentionally overwritten.

Suggested resolution:

Change [class.copy.ctor] p15 as indicated:

The implicitly-defined copy/move constructor for a union X copies the object value representation ([basic.types.general]) of X. [...]

Change [class.copy.assign] p13 as indicated:

The implicitly-defined copy/move assignment operator for a union X copies the object value representation ([basic.types.general]) of X. [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions