纯虚函数是否可以防止隐式生成的移动构造函数?

6 c++ language-lawyer move-semantics c++11

#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");
Run Code Online (Sandbox Code Playgroud)

(实时)
根据cppreference.com(据我所知),test应该有一个隐式生成的移动构造函数:

类T的隐式声明或默认移动构造函数被定义为删除以下任何一种情况:

  • T [= test]具有无法移动的非静态数据成员(已删除,不可访问或不明确的移动构造函数)
  • T具有无法移动的直接或虚拟基类(已删除,不可访问或不明确的移动构造函数)
  • T具有直接或虚拟基类,具有已删除或无法访问的析构函数
  • T是一个联合,并且具有带有非平凡复制构造函数的变体成员
  • (直到C++ 14)T有一个非静态数据成员或一个没有移动构造函数的直接或虚拟基础,这种移动构造函数不是可以轻易复制的.

为什么编译器不为其生成隐式移动构造函数test?为什么这样做test2呢?

Bar*_*rry 14

std::is_move_constructible检查是否可以从rvalue参数构造类型.test是一个抽象类类型.无论论证如何,它都无法构建.

  • @MartinD.是.事实上,我们知道它确实如此,因为`is_move_constructible <test2>`是真的. (3认同)