Assuming I have the following (invalid) code:
struct A {
A(A) {};
};
MSVC gives me:
error C2652: 'A' : illegal copy constructor: first parameter must not be a 'A'
Why does the compiler detect this as copy constructor, and not a regular constructor?
Chapter 12.8.2 of the C++ Standard says:
A non-template constructor for class X is a copy constructor if its first parameter is of type X& , const X& , volatile X& or const volatile X&
I would expect that the compiler detects the above method as regular constructor, just like
struct A {
A(B) {};
};
whereas B is another class.
Where is this behaviour defined?
N4140 [class.copy]/6
A declaration of a constructor for a class
X
is ill-formed if its first parameter is of type (optionally cv-qualified)X
and either there are no other parameters or else all other parameters have default arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With