c++copydestructorstdmove

If only the virtual destructor is declared as default, Is the copy constructor implicitly generated?


In the case of the example below Implicitly, the move constructor and move assignment operator are not created. I knew.

So, are the copy constructor and copy assignment operator generated?

Is the undefined copy constructor created implicitly?

class X
{
  public:
    virtual ~X() = default; 
}

The links I referenced are below:


Solution

  • are the copy constructor generated?

    The copy ctor is to be defaulted but it is now deprecated from class.copy.ctor#6. Clang also gives warning for the same. You might want to explicitly default the copy ctor like X(const X&) = default; to show the intention and prepare for future removal.

    If the class definition does not explicitly declare a copy constructor, a non-explicit one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defaulted ([dcl.fct.def]). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor ([depr.impldec]).

    (emphasis mine)

    And since you do have a user-declared destructor, this is deprecated.

    Similarly copy assignment operator for a class with nothing but a user-declared dtor is also deprecated . From class.copy.assign#2:

    If the class definition does not explicitly declare a copy assignment operator, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy assignment operator is defined as deleted; otherwise, it is defaulted ([dcl.fct.def]). The latter case is deprecated if the class has a user-declared copy constructor or a user-declared destructor ([depr.impldec]).