-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Clang error: lambda-coroutine with operator new in promise_type #84064
Comments
@llvm/issue-subscribers-coroutines Author: Andreas Fertig (andreasfertig)
Hello,
the following code is accepted by g++ and MSVC, but rejected by Clang: https://compiler-explorer.com/z/hG58nq7TE (lambda) Without the https://compiler-explorer.com/z/dnEhsj6hP With my reading of http://eel.is/c++draft/dcl.fct.def.coroutine#4 and http://eel.is/c++draft/dcl.fct.def.coroutine#9.1 Clang is wrong in both cases. It should accept the first and second example but reject the third. |
@llvm/issue-subscribers-clang-frontend Author: Andreas Fertig (andreasfertig)
Hello,
the following code is accepted by g++ and MSVC, but rejected by Clang: https://compiler-explorer.com/z/hG58nq7TE (lambda) Without the https://compiler-explorer.com/z/dnEhsj6hP With my reading of http://eel.is/c++draft/dcl.fct.def.coroutine#4 and http://eel.is/c++draft/dcl.fct.def.coroutine#9.1 Clang is wrong in both cases. It should accept the first and second example but reject the third. |
I don't see clang rejecting your example for "struct and coroutine member function"? |
I also don't quite get why you expect the third to be rejected. The third has a |
The |
If it is the case, I feel like the root cause comes from how we treat lambdas. CC: @cor3ntin |
in |
Hello,
Yes! Sorry, I was tired and seemed to have looked at something different. Strike the second example.
Yes, but according to http://eel.is/c++draft/dcl.fct.def.coroutine#4, in case of a member function, the first parameter is an lvalue of
I thought so, too! If I find the time, I'll try to look into it. Andreas |
It turns out that it introduced in 9860622, which is pretty early. However, after I removed that limitation, I fall into the diagnostic at line 1434, which shows the type of this is Null llvm-project/clang/lib/Sema/SemaExprCXX.cpp Lines 1417 to 1438 in 6e27dd4
I don't have an idea what happened. |
Great. If you'd like to take it, you can assign this to yourself. Then we can avoid repeating ourselves. |
We probably need a CXXThisScopeRAII so that |
hmm it doesn't work if I put that in front of Maybe I need to investigate more. Or if you have time, I guess you can look into this directly. |
I don't know how to assign this issue to myself, but I'm on it. I have a version that works. I'm running the test suit on it to see whether it breaks other stuff. Andreas |
Fix llvm#84064 According to http://eel.is/c++draft/dcl.fct.def.coroutine#9 the first parameter for overload resolution of `operator new` is `size_t` followed by the arguments of the coroutine function. http://eel.is/c++draft/dcl.fct.def.coroutine#4 states that the first argument is the lvalue of `*this` if the coroutine is a member function. Before this patch, Clang handled class types correctly but ignored lambdas. This patch adds support for lambda coroutines with a `promise_type` that implements a custom `operator new`. The patch does consider C++23 `static operator()`, which already worked as there is no `this` parameter.
Fix llvm#84064 According to http://eel.is/c++draft/dcl.fct.def.coroutine#9 the first parameter for overload resolution of `operator new` is `size_t` followed by the arguments of the coroutine function. http://eel.is/c++draft/dcl.fct.def.coroutine#4 states that the first argument is the lvalue of `*this` if the coroutine is a member function. Before this patch, Clang handled class types correctly but ignored lambdas. This patch adds support for lambda coroutines with a `promise_type` that implements a custom `operator new`. The patch does consider C++23 `static operator()`, which already worked as there is no `this` parameter.
Fix llvm#84064 According to http://eel.is/c++draft/dcl.fct.def.coroutine#9 the first parameter for overload resolution of `operator new` is `size_t` followed by the arguments of the coroutine function. http://eel.is/c++draft/dcl.fct.def.coroutine#4 states that the first argument is the lvalue of `*this` if the coroutine is a member function. Before this patch, Clang handled class types correctly but ignored lambdas. This patch adds support for lambda coroutines with a `promise_type` that implements a custom `operator new`. The patch does consider C++23 `static operator()`, which already worked as there is no `this` parameter.
#84193) Fix #84064 According to http://eel.is/c++draft/dcl.fct.def.coroutine#9 the first parameter for overload resolution of `operator new` is `size_t` followed by the arguments of the coroutine function. http://eel.is/c++draft/dcl.fct.def.coroutine#4 states that the first argument is the lvalue of `*this` if the coroutine is a member function. Before this patch, Clang handled class types correctly but ignored lambdas. This patch adds support for lambda coroutines with a `promise_type` that implements a custom `operator new`. The patch does consider C++23 `static operator()`, which already worked as there is no `this` parameter.
This is a follow-up of llvm#84064. It turned out that a coroutine-lambda with a `promise_type` and a user-defined constructor ignores the `this` pointer. Per http://eel.is/c++draft/dcl.fct.def.coroutine#4, in such a case, the first parameter to the constructor is an lvalue of `*this`.
This is a follow-up of llvm#84064. It turned out that a coroutine-lambda with a `promise_type` and a user-defined constructor ignores the `this` pointer. Per http://eel.is/c++draft/dcl.fct.def.coroutine#4, in such a case, the first parameter to the constructor is an lvalue of `*this`.
This is a follow-up of llvm#84064. It turned out that a coroutine-lambda with a `promise_type` and a user-defined constructor ignores the `this` pointer. Per http://eel.is/c++draft/dcl.fct.def.coroutine#4, in such a case, the first parameter to the constructor is an lvalue of `*this`.
This is a follow-up of llvm#84064. It turned out that a coroutine-lambda with a `promise_type` and a user-defined constructor ignores the `this` pointer. Per http://eel.is/c++draft/dcl.fct.def.coroutine#4, in such a case, the first parameter to the constructor is an lvalue of `*this`.
Hello,
the following code is accepted by g++ and MSVC, but rejected by Clang:
https://compiler-explorer.com/z/hG58nq7TE (lambda)
https://compiler-explorer.com/z/7WM7eP3h7 (struct and coroutine member function)
Without the
This
parameter foroperator new
and passing another parameter, the code is accepted by Clang but rejected by g++ and MSVC:https://compiler-explorer.com/z/dnEhsj6hP
With my reading of http://eel.is/c++draft/dcl.fct.def.coroutine#4 and http://eel.is/c++draft/dcl.fct.def.coroutine#9.1 Clang is wrong in both cases. It should accept the first and second example but reject the third.
The text was updated successfully, but these errors were encountered: