DECL_EXCEPTION_REFCOUNT (arg)
= size_binop (PLUS_EXPR, DECL_EXCEPTION_REFCOUNT (arg), size_one_node);
++ctx->global->uncaught_exceptions;
+ /* Don't cache calls which rethrow, they depend on the current
+ exception which might be caught in the caller. */
+ ctx->global->metafns_called = true;
*jump_target = arg;
return void_node;
case CXA_BAD_CAST:
*non_constant_p = true;
return call;
}
+ /* Don't cache calls which call __builtin_uncaught_exceptions (),
+ they depend on the current uncaught exceptions which might
+ be the state from their caller. */
+ ctx->global->metafns_called = true;
return build_int_cst (integer_type_node,
ctx->global->uncaught_exceptions);
case BUILTIN_CURRENT_EXCEPTION:
size_one_node);
arg = fold_convert (ptr_type_node, build_address (arg));
}
+ /* Don't cache calls which call __builtin_current_exception (),
+ they depend on the current exception which might be caught
+ in the caller. */
+ ctx->global->metafns_called = true;
return build_constructor_single (TREE_TYPE (decl), fld, arg);
}
case STD_RETHROW_EXCEPTION:
--- /dev/null
+// PR c++/126508
+// { dg-do compile { target c++26 } }
+
+constexpr int
+foo ()
+{
+ return __builtin_uncaught_exceptions ();
+}
+
+constexpr int
+bar ()
+{
+ return __builtin_uncaught_exceptions ();
+}
+
+struct A { constexpr A () : a (0) {} constexpr ~A () { if (foo () != a) asm (""); } int a; };
+struct B { constexpr B () : b (0) {} constexpr ~B () { if (bar () != b) asm (""); } int b; };
+
+constexpr bool
+baz ()
+{
+ {
+ A a;
+ }
+ try
+ {
+ A a;
+ B b;
+ a.a = 1;
+ b.b = 1;
+ throw 42;
+ }
+ catch (...)
+ {
+ }
+ {
+ A a;
+ B b;
+ }
+ return true;
+}
+
+static_assert (baz ());
--- /dev/null
+// PR c++/126508
+// { dg-do compile { target c++26 } }
+
+#include <exception>
+
+constexpr std::exception_ptr
+foo (const std::exception_ptr &x)
+{
+ return x;
+}
+
+constexpr bool
+baz ()
+{
+ std::exception_ptr a = std::make_exception_ptr (42);
+ auto b = foo (a);
+ auto c = foo (a);
+ auto d = foo (a);
+ return true;
+}
+
+static_assert (baz ());