#include <type_traits> struct test { virtual void foo() noexcept = 0; }; struct test2 : test { void foo() noexcept override final {} }; // fails static_assert(std::is_move_constructible<test>::value, "test not move constructible"); // succeeds static_assert(std::is_move_constructible<test2>::value, "test2 not move constructible");
(Live)
According to cppreference.com (and as I understand it), test should have an implicitly generated move constructor:
An implicitly or defaulted move constructor for class T is defined as deleted in any of the following statements:
- T [= test] has non-static data elements that cannot be moved (deleted, inaccessible or ambiguous move constructors).
- T has a direct or virtual base class that cannot be moved (deleted, inaccessible or ambiguous move constructors)
- T has a direct or virtual base class with a remote or inaccessible destructor
- T is a union and has a variant member with a nontrivial copy constructor
- (before C ++ 14) T has a non-static data element or a direct or virtual base without a move constructor that cannot be trivially copied.
Why doesn't the compiler create an implicit move constructor for test ? Why does he do this for test2 ?
source share