C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function only accepts parameter that will persist

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 6 May 2024 19:45:55 +0100
On Mon, May 6, 2024 at 7:15 PM Thiago Macieira wrote:
>
> On Monday 6 May 2024 10:19:23 GMT-7 Frederick Virchanza Gotham via Std-
>
> Why would it ever need to mandate that? Why should EVERY SINGLE constexpr
> function have to have a consteval-only portion?


What I meant was:
    For a constexpr function that contains consteval-only portions,
said function must behave exactly as though you had copy-pasted all of
those consteval-only portions out into a separate "consteval"
function.

So the following function:

constexpr bool Func(int a, int const b)
{
    a += b;
    if consteval { ++a; }
    a -= 3;
}

when invoked in a constant-evaluated context, must behave exactly the same as:

consteval bool Func(int a, int const b)
{
    a += b;
    ++a;
    a -= 3;
}

This would make sense.

Received on 2024-05-06 18:46:01