Why does std::is_nothrow_move_assignable depend on the presence of a destructor?

233 views Asked by At

I have a class like the following:

class C {
public:
    C() : ... {}
    ~C() {}

    Member_1 m_1;
    // ...
    Member_N m_N;
};

The two special member functions shown are the only ones declared.

Now,

static_assert(std::is_nothrow_move_assignable<Member_1>::value);
// ...
static_assert(std::is_nothrow_move_assignable<Member_N>::value);

are all satisfied. Yet,

static_assert(std::is_nothrow_move_assignable<C>::value);

asserts. If I remove the empty destructor, it passes.

What does the destructor have to do with the move assignment operator? New Rule of Five?

Compiler is GCC 4.9.3 with -std=c++0x (for historic reasons).

1

There are 1 answers

0
T.C. On BEST ANSWER

A user-declared destructor suppresses the implicit generation of move special member functions ([class.copy]/p9, 20). Thus, C only has a copy constructor and a copy assignment operator; the latter is used to perform the "move" assignment, and presumably could throw.