Issue 91509
Summary [Clang] [Sema] C++23 consteval if not recognised as immediate function context in templated function
Labels clang
Assignees
Reporter MitalAshok
    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) {
      | ^
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to