Why is it impossible to explicitly specify a copy constructor with a mutable argument?

I could not find where the standard states that it is explicitly forbidden to use the copy constructor and copy destination with an argument volatile&or const volatile&, for example:

struct A{
   A(const volatile A&) =default; // fails to compile on (all) compilers
   };

There is no such restriction in [dcl.fct.def.default], and [class.copy] indicates that it A(const volatile A&)is a copy constructor.

Note. I'm just looking for a place in the text of the standard that defines this behavior.

+4
source share
1 answer

You are in the right sections, but do not notice some important bullets.

[dcl.fct.def.default] / 1 :

Definition of a function of the form:

...

. ,

  • ( , , - , , " ", - ) , ,

[class.copy.ctor]/7:

X

X::X(const X&)

M ( ) , const & const volatile M &. 119

X::X(X&)

...
119) , lvalue; >

, c'tor :

struct A {
   A(const A&) = default;
};

struct B {
   B(B&) = default;
};

, A(const volatile A&) . , c'tor copy c'tor.

+8

Source: https://habr.com/ru/post/1686853/


All Articles