<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/91509>91509</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] [Sema] C++23 consteval if not recognised as immediate function context in templated function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          MitalAshok
      </td>
    </tr>
</table>

<pre>
    Consider <https://godbolt.org/z/qTexTzKrb>:

```c++
consteval int f(int) { return 0; }

template<typename T>
constexpr int g(int x) {
    if consteval {
        return f(x);
    }
    return 1;
}

int h(int x) {
    return g<void>(x);
}
```

The invocation being inside the `if consteval` means it's in an immediate function context ([[expr.const]p(16.3)](https://eel.is/c++draft/expr.const#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) {
      | ^
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU1zozgQ_TXtS1dcIBljHzjE9viytafNHxDQgHaE5EXC48whv32r5S-SdVKpdVECQ-vp9eunlvJet5aogGwD2W6mxtC5ofhTB2Wefed-zkpXvxZbZ72uaUCQ2y6Egwf5DGIPYt-6unQmzN3Qgtj_BrH_54VOL7__GEqQPzgs2UFyHZfJ-apAbPiKbytnfaCjMqhtwAbEStsAYo2Qb3CgMA4WE5AbhHw3RQvUH4wKBHIbXg9kVU_4wotOUE-HIaK2Z1Q8XXDPMYiIusE7gXdf-HdZnknxVJCT7zc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