C++ Logo

std-proposals

Advanced search

[std-proposals] [[unevaluated]]

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 19 May 2026 18:40:23 +0000
[[unevaluated]] auto Func(void)
{
    if constexpr ( some_constant0 )
    {
        return SomeType{};
    }
    else
    {
        return SomeOtherType{ 0xFF };
    }
}

The idea is that the compiler will forbid the use of Func outside of an
unevaluated context.

One trick people are using is to put this in the body:

    static_assert(1 == 2, "Func must only be used in an unevaluated
context");

But I think we'd be better off with an attribute that tells the compiler
exactly what we have in mind. And of course the attribute would ensure that
the function is not emitted in the object file.

Received on 2026-05-19 18:40:29