]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Make std::rethrow_if_nested work without RTTI
authorJonathan Wakely <jwakely@redhat.com>
Thu, 12 May 2022 13:18:06 +0000 (14:18 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 13 May 2022 19:39:59 +0000 (20:39 +0100)
commitc470f3ea86a28caacb9e9124307c4a03b2396288
tree5fe55f44b217038f4ff32e08a2daf5387186ac31
parente97e99296505e6015bc9e281364818bb89ca8a49
libstdc++: Make std::rethrow_if_nested work without RTTI

This allows std::rethrow_if_nested to work with -fno-rtti by not
attempting the dynamic_cast if it requires RTTI, since that's ill-formed
with -fno-rtti. The cast will still work if a static upcast to
std::nested_exception is allowed.

Also use if-constexpr to avoid the compile-time overload resolution (and
SFINAE) and run-time dispatching for std::rethrow_if_nested and
std::throw_with_nested.

Also add better doxygen comments throughout the file.

libstdc++-v3/ChangeLog:

* libsupc++/nested_exception.h (throw_with_nested) [C++17]: Use
if-constexpr instead of tag dispatching.
(rethrow_if_nested) [C++17]: Likewise.
(rethrow_if_nested) [!__cpp_rtti]: Do not use dynamic_cast if it
would require RTTI.
* testsuite/18_support/nested_exception/rethrow_if_nested-term.cc:
New test.
libstdc++-v3/libsupc++/nested_exception.h
libstdc++-v3/testsuite/18_support/nested_exception/rethrow_if_nested-term.cc [new file with mode: 0644]