Date
2022-02-18.07:47:23
Message id
5797

Content

Subclause 9.6.2 [dcl.fct.def.default] paragraph 1 specifies:

A function that is explicitly defaulted shall
  • ...
  • have the same declared function type (except for possibly differing ref-qualifiers and except that in the case of a copy constructor or copy assignment operator, the parameter type may be “reference to non-const T”, where T is the name of the member function's class) as if it had been implicitly declared,
  • ...

Therefore, the following code is ill-formed:

  struct S
  {
   int i;
   S(const S&) = default;
   S(const volatile S&) = default; // ill-formed
  };

  volatile S s1;
  S s2(s1);

However, C.7.7 [diff.class] paragraph 2 mentions the ability to default such a constructor:

If volatile semantics are required for the copy, a user-declared constructor or assignment must be provided. [ Note: This user-declared constructor may be explicitly defaulted. —end note]