This code compiles on gcc and msvc but not with clang from C++20 on:
#include <type_traits>
class IBase {
protected:
IBase() noexcept = default;
public:
virtual ~IBase() noexcept = default;
};
class Derived : public IBase {
public:
virtual ~Derived() noexcept(
std::is_nothrow_destructible<IBase>::value) override = default;
};
Up to C++17 included, gcc, msvc and clang compile this code but from C++20, clang rejects it with error: exception specification is not available until end of class definition
.
Is it a clang bug or, on the contrary, a change in exception specification in C++20? How can I fix this code?
[EDIT] Based on the comments, here is a "more minimal reproducible example":
class IBase {
public:
virtual ~IBase() noexcept = default;
};
class Derived : public IBase {
public:
~Derived() noexcept(true) override = default;
};
Notice that the inheritance and both = default
seem necessary to trigger the error.
virtual ~Derived() noexcept(true) override = default;
gives the same error might simplify analysis. (I don't know what's going on yet either) – Typefacevirtual
in the derived class to make it even more minimal :-) Interesting question. – Natalia=default
the~IBase()
. Also~Derived() noexcept = default;
(instead of~Derived() noexcept(true) = default;
) passes regardless of~IBase
being defaulted. This smells like an error in clang. – Attica