Question

Looking here on StackOverflow I found out that on Clang++ when using C++11 standard, if you have defined a move constructor to your class, the implicit constructor generation is disabled, i.e. copy constructor is "explicted deleted".

Is there any way to disable this behavior?

Also, is this behavior standardized? Because I don't have the same behavior in GCC.

Was it helpful?

Solution

Is there any way to disable this behavior?

No. But you can always:

A(const A&) = default;

Though I'm unsure if clang currently fully implements defaulted copy constructors.

Also, is this behavior standardized?

Yes. [class.copy]/p7:

If the class definition does not explicitly declare a copy constructor, 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; ...

...

Because I don't have the same behavior in GCC.

Which version? I would've guessed that the latest gcc version had the same behavior as clang. But I do not have it available to experiment with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top