[Clang] [Sema] C++23 consteval if not recognised as immediate function context in templated function (original) (raw)

Consider https://godbolt.org/z/qTexTzKrb:

consteval int f(int) { return 0; }

template constexpr int g(int x) { if consteval { return f(x); } return 1; }

int h(int x) { return g(x); }

The invocation being inside the if consteval means it's in an immediate function context ([expr.const]p(16.3)), so it shouldn't be immediate-escalating, and g<void> should not be an immediate function, yet Clang complains that it is.

<source>:12:12: error: call to immediate function 'g<void>' is not a constant expression
   12 |     return g<void>(x);
      |            ^
<source>:6:16: note: 'g<void>' is an immediate function because its body contains a call to a consteval function 'f' and that call is not a constant expression
    6 |         return f(x);
      |                ^~~~
<source>:12:20: note: function parameter 'x' with unknown value cannot be used in a constant expression
   12 |     return g<void>(x);
      |                    ^
<source>:11:11: note: declared here
   11 | int h(int x) {
      |           ^