Destructor makes constructor noexcept invalid

2013-02-04
2013-06-06
  • Anders Eklund
    Anders Eklund
    2013-02-04

    Using minGW 64 (x64-4.7.2-release-posix-sjlj-rev8.7z).

    Found a peculiar thing.

    If one create constuctors in C++ with the noexcept directive, they are found as nothrow.
    For example.

    class X
    {
    public:
      X(X&& x) noexcept {};
    };

    the statement std::is_nothrow_move_constructible<X>::value evaluates to true

    But as soon you add a destructor without a noexcept specifier, the same statement is false.
    If you add a destructor with the noexcept specifier, the statement becomes true again.
    You get the same result if you use a noexcept(expression) statement.

    I'm not sure if this follows C++11 specifications or not, but I have not seen any information about this anywhere.
    Any comment about this? I find it strange that an object is not nothrow constructible only becuase it's not nothrow destructible.

    /Anders