On Fri, 11 Jul 2025 at 14:02, Jonathan Wakely <jwak...@redhat.com> wrote: > > The if-consteval branches in std::make_exception_ptr and > std::exception_ptr_cast use a try-catch block, which gives an error for > -fno-exceptions. Just make them return a null pointer at compile-time > when -fno-exceptions is used, because there's no way to get an active > exception with -fno-exceptions. > > For std::exception_ptr_cast the consteval branch doesn't depend on RTTI > being enabled, so we can move the check for __cpp_rtti into the runtime > branch. We can also remove the #else group and just fall through to the > return nullptr statement if there was no return from whichever branch of > the if-consteval was taken.
Actually for exception_ptr_cast maybe we want: #ifdef __cpp_rtti if not consteval { const type_info &__id = typeid(const _Ex&); return static_cast<const _Ex*>(__p._M_exception_ptr_cast(__id)); } #endif #ifdef __cpp_exceptions if (__p._M_exception_object) try { std::rethrow_exception(__p); } catch (const _Ex& __exc) { return &__exc; } catch (...) { } #endif return nullptr; So for runtime calls with -frtti we try to use that, and then unless -fno-exceptions is used we just use try-catch. That will allow it to work at runtime with either -fno-rtti or -fno-exceptions (but not both). For compile-time -fno-rtti doesn't matter, but -fno-exceptions makes it return null.