Created on 2025-09-05.00:00:00 last changed 1 month ago
Proposed resolution (approved 2025-11-05):
Change in 11.4.5.3 [class.copy.ctor] paragraph 11 as follows:
A copy/move constructor for class X is trivial if it is not user-provided and ifotherwise the copy/move constructor is non-trivial.
- class X has no virtual functions (11.7.3 [class.virtual]) and no virtual base classes (11.7.2 [class.mi]), and
- the constructor selected to copy/move each direct base class subobject is a direct member of that base class and is trivial, and
- for each non-static data member of X that is of class type (or array thereof), the constructor selected to copy/move that member is trivial;
Change in 11.4.6 [class.copy.assign] paragraph 9 as follows:
A copy/move assignment operator for class X is trivial if it is not user-provided and ifotherwise the copy/move assignment operator is non-trivial.
- class X has no virtual functions (11.7.3 [class.virtual]) and no virtual base classes (11.7.2 [class.mi]), and
- the assignment operator selected to copy/move each direct base class subobject is a direct member of that base class and is trivial, and
- for each non-static data member of X that is of class type (or array thereof), the assignment operator selected to copy/move that member is trivial;
(From submission #759.)
Consider:
struct B0 { int b0; };
struct B {
B &operator=(const B &) = default;
int x;
};
struct D : B0, B {
using B::operator=;
private:
D &operator=(const D &) && = default;
};
struct Q {
Q &operator=(const Q &) = default;
D d;
};
According to the rules, Q::operator= is trivial, but it does not copy the d.B0::b0 member of Q. Implementations disagree and copy that member regardless.
We can make Q::operator= non-trivial or deleted. We can also make that assignment operator copy all subobjects, even though overload resolution on the base classes clearly is at odds with that outcome.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2025-11-07 07:33:50 | admin | set | status: tentatively ready -> ready |
| 2025-11-05 18:50:44 | admin | set | messages: + msg8218 |
| 2025-11-05 18:50:44 | admin | set | status: review -> tentatively ready |
| 2025-11-05 13:55:49 | admin | set | status: open -> review |
| 2025-09-05 00:00:00 | admin | create | |