[PATCH] c++, libstdc++, v5: Implement C++26 P3068R5 - constexpr exceptions [PR117785]

Jason Merrill jason@redhat.com
Thu Jul 10 17:20:52 GMT 2025


On 7/10/25 4:05 AM, Jakub Jelinek wrote:
> On Wed, Jul 09, 2025 at 06:45:41PM -0400, Jason Merrill wrote:
>>> +	  && reduced_constant_expression_p (val))
>>
>> And a value doesn't need to be constant to be printable, we should be able
>> to print it unconditionally.
> 
> Sure, the question is if printing non-constant value is better for users.
> The change to do unconditionally the %qE results in
> /usr/src/gcc/gcc/testsuite/g++.dg/cpp26/constexpr-eh12.C:71:49: error: uncaught exception '(E*)(& heap )'
> while previously it was
> /usr/src/gcc/gcc/testsuite/g++.dg/cpp26/constexpr-eh12.C:71:49: error: uncaught exception of type 'E*'
> I've kept the conditional for now but if you really want that change, can remove it
> in the 2 spots and tweak constexpr-eh12.C test's expectations.

Fair enough, we can leave it.

>       case CLEANUP_STMT:
>         r = cxx_eval_constant_expression (ctx, CLEANUP_BODY (t), lval,
>   					non_constant_p, overflow_p,
>   					jump_target);
> -      if (!CLEANUP_EH_ONLY (t) && !*non_constant_p)
> +      if ((!CLEANUP_EH_ONLY (t) || throws (jump_target)) && !*non_constant_p)
>   	{
>   	  iloc_sentinel ils (loc);
> +	  tree jmp_target = NULL_TREE;
>   	  /* Also evaluate the cleanup.  */
>   	  cxx_eval_constant_expression (ctx, CLEANUP_EXPR (t), vc_discard,
> -					non_constant_p, overflow_p);
> +					non_constant_p, overflow_p,
> +					&jmp_target);
> +	  if (throws (&jmp_target))
> +	    {
> +	      if (throws (jump_target))
> +		{
> +		  /* [except.throw]/9 - If the exception handling mechanism
> +		     handling an uncaught exception directly invokes a function
> +		     that exits via an exception, the function std::terminate is
> +		     invoked.  */
> +		  if (!ctx->quiet)
> +		    {
> +		      auto_diagnostic_group d;
> +		      diagnose_std_terminate (loc, ctx, *jump_target);
> +		      inform (loc, "destructor exited with an exception");
> +		    }
> +		  *non_constant_p = true;
> +		  *jump_target = NULL_TREE;
> +		  r = NULL_TREE;
> +		}
> +	      else
> +		*jump_target = jmp_target;

Can't you use merge_jump_target here, too?

OK with that change.

Jason



More information about the Libstdc++ mailing list