According to cppreference, deriving from a non-movable class should make a derived class non-movable, too. Then why does std::is_move_constructible_v
return true for the derived class?
class NonMovable{
public:
NonMovable(const NonMovable&) = default;
NonMovable(NonMovable&&) = delete;
NonMovable& operator = (const NonMovable&) = default;
NonMovable& operator = (NonMovable&&) = delete;
NonMovable() = default;
};
class Derived : public NonMovable{};
int main(){
std::cout << std::is_move_constructible_v<NonMovable> << "\n"; // 0
std::cout << std::is_move_constructible_v<Derived> << "\n"; // 1
}
const T&
arguments, satisfystd::is_move_constructible
. – Phocineis_move_constructible_v<NonMovable>
isfalse
. – Mcmathstd::cout << std::is_move_constructible_v<NonMovable> << "\n";
would be1
but it shows0
. – RedoubleNonMovable
, the move constructor is explicitly deleted. An explicitly deleted function still participates in overload resolution (but if it ends up winning, you get a compiler error). But inDerived
, the move constructor is defaulted to deleted, so it simply doesn't participate at all. (and therefore cannot win a game that it doesn't play). "A defaulted move special member function that is defined as deleted is excluded from the set of candidate functions in all contexts. – Hydrocele