samedi 4 mars 2017

Unreasonably deleted move constructor

I have a class with explicitely deleted copy constructor named, let's say, NonCopyable. Then there's a class Base1 with a member of type NonCopyable. And another class Base2 with Base1 as parent. And finally - a Derivative class which parent is Base2.

Since NonCopyable is non-copyable, it's obvious that Base1, Base2 and Derivative will be also non-copyable. But it seems like there's been also move constructor (and assign operator) deleted.

Test it here:

Following line gives those errors:
Derived d1, d2 = std::move(d1);

GCC: 'Derived::Derived(Derived&&)' is implicitly deleted because the default definition would be ill-formed: class Derived :
the rest of errors just claims that Base1 and Base2 copy ctors are implicitly deleted which is not weird

MSVC: error C2280: 'Derived::Derived(const Derived &)': attempting to reference a deleted function

In provided links there's also commented lines which gives similar errors. Please uncomment them to see more errors I'd like to show you (e.g. with remove_if uncommented it complains about deleted move (on GCC) /copy (on MSVC) assign operator).
What I want to achieve is make Derivative (and its bases also) moveable, but not copyable.

I'm working with Visual Studio 2015 and getting exactly the same error as in the msvc link I provided, but I'm not sure what version of MSVC is used to compile on rextester.com.

Aucun commentaire:

Enregistrer un commentaire