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: Sat, 4 May 2024 14:44:13 +0100
On Friday, May 3, 2024, Sebastian Wittmeier wrote:

> Up till now, it is the decision of the compiler, whether to evaluate those
> expressions in compile-time or runtime.
>
> This was chosen on purpose.
>
> *"must be a compile-time constant."* would contradict this philosophy.
>


I wonder is it foreseeable in the future that the following would be valid
code for a program that ends with EXIT_SUCCESS?

template<int i>
bool Func(void)
{
    return 666 == i;
}

constexpr bool Func2(int const a)
{
    if consteval
    {
        return Func<a>();
    }
    else
    {
        return false;
    }
}

constexpr int monkey = 665;

int main(void)
{
    return !Func2( monkey + 1 );
}

Received on 2024-05-04 13:44:16