'Why having both default destructor and vector member prevents class to be "nothrow movable constructible"?

Given the following code:

#include <iostream>
#include <vector>
#include <type_traits>

class Test {
public:
    ~Test() = default;
    std::vector<int> m_vector;
};


int main() {
    std::cout << std::is_nothrow_move_constructible_v<Test> << std::endl;
    return 0;
}

It outputs 0, meaning the Test class can't be "nothrow moved". However, if I remove either ~Test() or m_vector then it returns 1.

How to explain this please?

For reference, I'm using clang++-7 with C++17.



Solution 1:[1]

When you define a user declared destructor, the class will not have an implicitly generated move constructor. Hence, moving will invoke copy constructor. The copy constructor of std::vector is potentially throwing, hence the implicit copy constructor of Test will also be potentially throwing.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eerorika