0

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).

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
  • Mark destructor as no except. – Jarod42 Jun 24 '15 at 19:34
  • 1
    @Jarod42: destructors are implicitly noexcept – Marc Mutz - mmutz Jun 24 '15 at 19:35
  • 2
    Could this be related : https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56191? (or simply http://stackoverflow.com/questions/15721544/destructors-and-noexcept which points there) – Alexandre C. Jun 24 '15 at 19:36
  • Please provide a simple, self contained, compiling example that demonstrates the error in question. My initial attempt (where I set a member to `int`) did not generate the error in question. @AlexandreC. at first look, that bug seems to be fixed in 4.9.2 – Yakk - Adam Nevraumont Jun 24 '15 at 20:05

1 Answers1

5

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.

T.C.
  • 133,968
  • 17
  • 288
  • 421