-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lambda call should propagate as immediate function when the body is immediate-escalating expression #92547
Comments
The lack of code gen with GCC is an optimization. GCC still also allows This should be the expected behaviour as |
@llvm/issue-subscribers-clang-codegen Author: Nhat Nguyen (changkhothuychung) Should clang not generate the lambda call operator for this lambda call? According to https://eel.is/c++draft/expr.const#18, From https://eel.is/c++draft/expr.const#17, the call to f() is an immediate-escalating expression. (2) (1) and (2) will make the call to consteval auto f()
{
return 1;
}
auto l = [](){
return f();
};
int main()
{
auto x = l();
} |
Oh right. Now I think more about it, can you give me an example which is an immediate invocation and not a constant expression? I missed the constant expression part when I created this issue, and now I cant think of one example. Thanks! |
@changkhothuychung https://godbolt.org/z/doYzMMKb6 consteval auto f(int) {
return 1;
}
auto l = [](int i) {
return f(i); // Change to "f(0)" and it's no longer immediate-escalating
};
int main() {
auto x = l(0);
} |
Should clang not generate the lambda call operator for this lambda call?
According to https://eel.is/c++draft/expr.const#18,
the call operator of a lambda that is not declared with the consteval specifier is an immediate-escalating function
(1)From https://eel.is/c++draft/expr.const#17, the call to f() is an immediate-escalating expression. (2)
(1) and (2) will make the call to
l()
an immediate function and assembly code should not generate assembly code for the call operator. gcc seems to do ithttps://godbolt.org/z/vn6fh1fE5
The text was updated successfully, but these errors were encountered: