c++destructortype-traitsmoveabletype

Why class with destructor is not trivially move constructible?


Why is this class:

class test_type {
public:
    ~test_type() {
        std::cout << "~()\n";
    }
};

// fails
static_assert(std::is_trivially_move_constructible_v<test_type>, "");

not trivially move constructible?


Solution

  • Why class with destructor is not trivially move constructible?

    Because the standard says so:

    [class.prop]

    A trivially copyable class is a class:

    • that has at least one eligible copy constructor, move constructor, copy assignment operator, or move assignment operator ([special], [class.copy.ctor], [class.copy.assign]),
    • where each eligible copy constructor, move constructor, copy assignment operator, and move assignment operator is trivial, and
    • that has a trivial, non-deleted destructor ([class.dtor]).