Date: Tue, 19 May 2026 20:46:58 +0100
On Tue, 19 May 2026 at 19:40, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:
>
> [[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.
>
Why? What's the actual use case? Why is it better than just using a
consteval function for the same purpose?
>
> 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");
>
That can't even be compiled, even if it's never used in any context,
evaluated or not.
>
> 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.
>
You get that with consteval.
std-proposals_at_[hidden]> wrote:
>
> [[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.
>
Why? What's the actual use case? Why is it better than just using a
consteval function for the same purpose?
>
> 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");
>
That can't even be compiled, even if it's never used in any context,
evaluated or not.
>
> 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.
>
You get that with consteval.
Received on 2026-05-19 19:47:17
