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

2024-10-26


2203. Defaulted copy/move constructors and UDCs

Section: 11.4.5.3  [class.copy.ctor]     Status: drafting     Submitter: Vinny Romano     Date: 2015-11-20

Consider:

  struct A
  {
    A();
    A(A&);
    explicit A(int);
    operator int() const;
  };
  struct B
  {
    B(B&& other);
    A a;
  };
  B::B(B&& other) : a(static_cast<B&&>(other).a) {}
  // B::B(B&& other) = default; // ill-formed

  void f(B& b1)
  {
    B b2 = static_cast<B&&>(b1);
  }

The user-defined move constructor is well-formed because B::a can be initialized via A::operator int() and A::A(int); however, Clang and GCC believe a defaulted one would be ill-formed.

What about the following, which is considered well-formed by compilers and calls A::A(C&&)?

  struct C {};

  struct A : C
  {
    A();
    A(A&);
    A(C&&);
  };
  struct B
  {
    B(B&& other);
    A a;
  };

  B::B(B&& other) = default;