On 7/17/25 6:25 PM, Jakub Jelinek wrote:
On Thu, Jul 17, 2025 at 05:31:27PM -0400, Jason Merrill wrote:
On 7/16/25 10:49 AM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
This patch implements consteval blocks, as specified by P2996.
They aren't very useful without define_aggregate, but having
a reviewed implementation on trunk would be great.

consteval {} can be anywhere where a member-declaration or
block-declaration can be.  The expression corresponding to it is:

    [] -> void static consteval compound-statement ()

and it must be a constant expression.

I've used cp_parser_lambda_expression to take care of most of the
parsing.  Since a consteval block can find itself in a template, we
need a vehicle to carry the block for instantiation.  Rather than
inventing a new tree, I'm using STMT_EXPR.

If we need something to trigger immediate evaluation, why not a
STATIC_ASSERT as the proposal suggests?

Isn't it a problem that static_assert constant evaluates it multiple times
(at least when it isn't constant)?

Hmm, perhaps, for stateful evaluation like define_aggregate. But we could address that with a flag on the STATIC_ASSERT like this patch puts on the STMT_EXPR.

Jason

Reply via email to