From 76cf7c1d431db822e5e7aea05ec621432889d3ad Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Wed, 1 Apr 2026 23:48:12 +0200 Subject: [PATCH] P3842R2 A conservative fix for constexpr uncaught_exceptions() and current_exception() Fixes NB US 67-118, FI-121, DE-120, GB 03-119, PL-012 (C++26 CD). --- source/support.tex | 48 +++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/source/support.tex b/source/support.tex index 203a1bf45f..1b5f2cd892 100644 --- a/source/support.tex +++ b/source/support.tex @@ -3837,18 +3837,19 @@ terminate_handler set_terminate(terminate_handler f) noexcept; [[noreturn]] void terminate() noexcept; - constexpr int uncaught_exceptions() noexcept; + int uncaught_exceptions() noexcept; using exception_ptr = @\unspec@; - constexpr exception_ptr current_exception() noexcept; + constexpr exception_ptr @\exposid{current-exception}@() noexcept; // \expos + exception_ptr current_exception() noexcept; [[noreturn]] constexpr void rethrow_exception(exception_ptr p); template constexpr exception_ptr make_exception_ptr(E e) noexcept; template constexpr const E* exception_ptr_cast(const exception_ptr& p) noexcept; template void exception_ptr_cast(const exception_ptr&&) = delete; - template [[noreturn]] constexpr void throw_with_nested(T&& t); - template constexpr void rethrow_if_nested(const E& e); + template [[noreturn]] void throw_with_nested(T&& t); + template void rethrow_if_nested(const E& e); } \end{codeblock} @@ -4073,7 +4074,7 @@ \indexlibraryglobal{uncaught_exceptions}% \begin{itemdecl} -constexpr int uncaught_exceptions() noexcept; +int uncaught_exceptions() noexcept; \end{itemdecl} \begin{itemdescr} @@ -4142,7 +4143,8 @@ \indexlibraryglobal{current_exception}% \begin{itemdecl} -constexpr exception_ptr current_exception() noexcept; +constexpr exception_ptr @\exposid{current-exception}@() noexcept; +exception_ptr current_exception() noexcept; \end{itemdecl} \begin{itemdescr} @@ -4212,15 +4214,9 @@ try { throw e; } catch(...) { - return current_exception(); + return @\exposid{current-exception}@(); } \end{codeblock} - -\pnum -\begin{note} -This function is provided for convenience and -efficiency reasons. -\end{note} \end{itemdescr} \indexlibraryglobal{exception_ptr_cast}% @@ -4256,18 +4252,18 @@ namespace std { class nested_exception { public: - constexpr nested_exception() noexcept; - constexpr nested_exception(const nested_exception&) noexcept = default; - constexpr nested_exception& operator=(const nested_exception&) noexcept = default; - constexpr virtual ~nested_exception() = default; + nested_exception() noexcept; + nested_exception(const nested_exception&) noexcept = default; + nested_exception& operator=(const nested_exception&) noexcept = default; + virtual ~nested_exception() = default; // access functions - [[noreturn]] constexpr void rethrow_nested() const; - constexpr exception_ptr nested_ptr() const noexcept; + [[noreturn]] void rethrow_nested() const; + exception_ptr nested_ptr() const noexcept; }; - template [[noreturn]] constexpr void throw_with_nested(T&& t); - template constexpr void rethrow_if_nested(const E& e); + template [[noreturn]] void throw_with_nested(T&& t); + template void rethrow_if_nested(const E& e); } \end{codeblock} @@ -4284,7 +4280,7 @@ \indexlibraryctor{nested_exception}% \begin{itemdecl} -constexpr nested_exception() noexcept; +nested_exception() noexcept; \end{itemdecl} \begin{itemdescr} @@ -4295,7 +4291,7 @@ \indexlibrarymember{rethrow_nested}{nested_exception}% \begin{itemdecl} -[[noreturn]] constexpr void rethrow_nested() const; +[[noreturn]] void rethrow_nested() const; \end{itemdecl} \begin{itemdescr} @@ -4307,7 +4303,7 @@ \indexlibrarymember{nested_ptr}{nested_exception}% \begin{itemdecl} -constexpr exception_ptr nested_ptr() const noexcept; +exception_ptr nested_ptr() const noexcept; \end{itemdecl} \begin{itemdescr} @@ -4318,7 +4314,7 @@ \indexlibrarymember{throw_with_nested}{nested_exception}% \begin{itemdecl} -template [[noreturn]] constexpr void throw_with_nested(T&& t); +template [[noreturn]] void throw_with_nested(T&& t); \end{itemdecl} \begin{itemdescr} @@ -4341,7 +4337,7 @@ \indexlibrarymember{rethrow_if_nested}{nested_exception}% \begin{itemdecl} -template constexpr void rethrow_if_nested(const E& e); +template void rethrow_if_nested(const E& e); \end{itemdecl} \begin{itemdescr}