samedi 16 novembre 2019

How to detect if a contructor is noexcept with a throwing destructor

The following code will fail to compile on most compilers:

#include <type_traits>

class Foo
{
    public:
    Foo() noexcept {}
    ~Foo() noexcept(false) {}
};

static_assert(std::is_nothrow_default_constructible_v<Foo>);

CppReference also states that this is common in compiler implementations, but provides no alternative. How can I test if a constructor is noexcept without the destructor influencing the result?

Aucun commentaire:

Enregistrer un commentaire