Files
gcc/libstdc++-v3/libsupc++
Jakub Jelinek 2b6c8467fe c++, libstdc++: Attempt to implement P3842R2 - A conservative fix for constexpr uncaught_exceptions() and current_exception()
The following patch attempts to implement the
P3842R2 - A conservative fix for constexpr uncaught_exceptions()
          and current_exception()
paper.  std::current_exception() and std::uncaught_exceptions() aren't
constexpr anymore (admittedly, they weren't declared that way in the
headers before either, but the FE magically treated them as such),
instead two new FE builtins are introduced so that one can get their
behavior before this patch when needed.  So, at constant evaluation
time they are constant evaluated and if they are not folded away,
they are transformed into std::current_exception() or
std::uncaught_exceptions() runtime calls during gimplification.

And nested_exception isn't constexpr anymore either.

2026-04-03  Jakub Jelinek  <jakub@redhat.com>

gcc/cp/
	* cp-tree.h (enum cp_built_in_function): Add
	CP_BUILT_IN_CURRENT_EXCEPTION and CP_BUILT_IN_UNCAUGHT_EXCEPTIONS.
	* tree.cc (builtin_valid_in_constant_expr_p): Handle
	those.
	* decl.cc (cxx_init_decl_processing): Build
	decls for CP_BUILT_IN_CURRENT_EXCEPTION and
	CP_BUILT_IN_UNCAUGHT_EXCEPTIONS.
	(require_deduced_type): Deduce CP_BUILT_IN_CURRENT_EXCEPTION
	return type.
	* cp-gimplify.cc (cp_gimplify_expr): Handle
	CP_BUILT_IN_CURRENT_EXCEPTION and CP_BUILT_IN_UNCAUGHT_EXCEPTIONS.
	* constexpr.cc (enum cxa_builtin): Remove STD_UNCAUGHT_EXCEPTIONS
	and STD_CURRENT_EXCEPTION, add BUILTIN_UNCAUGHT_EXCEPTIONS and
	BUILTIN_CURRENT_EXCEPTION, renumber some enumerators.
	(cxx_cxa_builtin_fn_p): Don't check for std::uncaught_exceptions
	nor std::current_exception.
	(cxx_eval_cxa_builtin_fn): Handle BUILTIN_UNCAUGHT_EXCEPTIONS
	and BUILTIN_CURRENT_EXCEPTION instead of STD_UNCAUGHT_EXCEPTIONS
	and STD_CURRENT_EXCEPTION.
	(cxx_eval_builtin_function_call): Handle
	CP_BUILT_IN_CURRENT_EXCEPTION and CP_BUILT_IN_UNCAUGHT_EXCEPTIONS.
	Do just one fndecl_builtin_p check for BUILT_IN_FRONTEND and
	switch on DECL_FE_FUNCTION_CODE.
gcc/testsuite/
	* g++.dg/cpp26/constexpr-eh3.C: Use __builtin_current_exception()
	instead of std::current_exception() and
	__builttin_uncaught_exceptions() instead of
	std::uncaught_exceptions().  Remove nested_exception related parts
	of the test.
	* g++.dg/cpp26/constexpr-eh8.C: Use __builtin_current_exception()
	instead of std::current_exception().
libstdc++-v3/
	* libsupc++/exception_ptr.h (std::make_exception_ptr): Use
	__builtin_current_exception() instead of current_exception() if
	the builtin exists.
	* libsupc++/nested_exception.h: Revert 2026-01-07 and 2025-07-10
	changes.
	* testsuite/18_support/exception_ptr/exception_ptr_cast.cc (test01):
	Use __builtin_current_exception instead of std::current_exception
	if __has_builtin(__builtin_current_exception).  Otherwise don't
	try to constant evaluate test01.

Reviewed-by: Jason Merrill <jason@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
2026-04-03 20:46:42 +02:00
..
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2025-10-05 17:14:49 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00
2026-01-02 09:56:11 +01:00