This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-10-11


3070. Trivial assignment can skip member subobjects

Section: 11.4.6  [class.copy.assign]     Status: open     Submitter: Jiang An     Date: 2025-09-05

(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.

Possible resolution

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 if otherwise the copy/move assignment operator is non-trivial.