| Issue |
235353
|
| Summary |
Clang rejects calling the function pointer conversion operator of a consteval lambda in a consteval context
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
Ferdi265
|
Calling the function pointer conversion operator of a consteval lambda causes a `cannot take address of consteval call operator of '(lambda)' outside of an immediate invocation` error:
```c++
int main() {
auto a = []consteval{return 3;};
constexpr auto b = (+a)();
}
```
Godbolt: https://godbolt.org/z/qq77YY39W (rejected by Clang, accepted by GCC)
or
```c++
int main() {
auto a = []consteval{return 3;};
constexpr auto b = ((int(*)())a)();
}
```
Godbolt: https://godbolt.org/z/131ozb99x (rejected by Clang, accepted by GCC)
Thanks to @efriedma-quic for finding this corner case in the discussion of #232458.
## Analysis
This appears to be because the function-pointer conversion operator of the lambda is immediate-escalating. @efriedma-quic pointed out that this is likely a gap or defect in the standard, as the relevant standards clauses don't specify that the conversion operator should be immediate(-escalating), unlike for the lambda special member functions and the function returned by this operator.
[\[expr.const.imm\]/3](https://eel.is/c++draft/expr.const.imm#3) defines an immediate-escalating function as either a lambda call operator, a non-user-provided defaulted function (that isn't already `consteval`), or a function that results from the instantiation of a templated entity defined with `constexpr` (that isn't a prospective destructor).
>From the letter of that that doesn't cover the conversion operator from [\[expr.prim.lambda.closure\]/11](https://eel.is/c++draft/expr.prim.lambda#closure-11), since it is neither a template declared `constexpr` nor a non-user-provided defaulted function. It is simply defined to exist as a 'normal' member function by the standard. [\[expr.prim.lambda.closure\]/11](https://eel.is/c++draft/expr.prim.lambda#closure-11) says the returned function F that is returned from the conversion operator is immediate if the call operator is immediate, but doesn't say whether the conversion operator itself should be.
I think that this only makes sense if the conversion operator should also be immediate if the call operator is immediate. Otherwise the standard would require a function to exist that is not immediate, not immediate-escalating, but require it to return a pointer to an immediate function, which would be ill-formed.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs