C++17 makes noexcept
part of a function's type. It also allows implicit conversions from noexcept
function pointers to potentially throwing function pointers.
void (*ptr_to_noexcept)() noexcept = nullptr;
void (*ptr_to_throwing)() = ptr_to_noexcept; // implicit conversion
http://eel.is/c++draft/expr.static.cast#7 says that static_cast
can perform the inverse of such a conversion.
void (*noexcept_again)() noexcept = static_cast<void(*)() noexcept>(ptr_to_throwing);
Unfortunately, both GCC and clang tell me otherwise: https://godbolt.org/z/TgrL7q
What is the correct way to do this? Are reinterpret_cast
and C style cast my only options?