CKTIS / C++
std::is_nothrow_destructible — checking non-throwing destruction
A <type_traits> trait that checks at compile time whether destruction is valid and cannot propagate an exception. std::is_nothrow_destructible<T>::value and std::is_nothrow_destructible_v<T> expose the same bool result.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <type_traits>
std::is_nothrow_destructible<T>::value
std::is_nothrow_destructible_v<T>std::is_nothrow_destructible<T> from <type_traits> is a class template exposing a constant bool member, ::value. std::is_nothrow_destructible_v<T> is a variable template providing shorthand for the same result. Use them in static_assert or if constexpr to check generic-code requirements without executing a destructor.
Scalar types such as int yield true even though they have no declared destructor or destructor exception specification. For a class type, the destructor must be accessible and not deleted, and its exception specification must not allow exceptions to propagate. For bounded arrays, the trait checks the element type after removing all array extents. References yield true: ending a reference's lifetime does not destroy the referred-to object. void, function types, and unknown-bound arrays yield false.
For a destructor, the trait checks the exception specification, not the correctness of the destructor body. An empty destructor with noexcept(false) still yields false. If an exception escapes a noexcept destructor, std::terminate is called; therefore, true does not guarantee successful program completion.
T must be a complete type, possibly cv-qualified void, or an unknown-bound array. Do not query this trait for a merely forward-declared class before its definition.
Examples
#include <iostream>
#include <type_traits>
struct Safe {
~Safe() noexcept {}
};
struct Risky {
~Risky() noexcept(false) {}
};
static_assert(std::is_nothrow_destructible<Safe>::value);
static_assert(!std::is_nothrow_destructible_v<Risky>);
static_assert(std::is_nothrow_destructible_v<Risky&>);
static_assert(!std::is_nothrow_destructible_v<void>);
int main() {
std::cout << std::boolalpha
<< std::is_nothrow_destructible<Safe>::value << '\n'
<< std::is_nothrow_destructible_v<Risky> << '\n';
}
Result
true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.