Title
Defaulted copy/move constructors and UDCs
Status
drafting
Section
11.4.5.3 [class.copy.ctor]
Submitter
Vinny Romano

Created on 2015-11-20.00:00:00 last changed 81 months ago

Messages

Date: 2022-02-18.07:47:23

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;
History
Date User Action Args
2018-02-27 00:00:00adminsetstatus: open -> drafting
2015-11-20 00:00:00admincreate