-
Notifications
You must be signed in to change notification settings - Fork 10.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
Coroutine ignores overloaded operator new
#54881
Comments
operator new
operator new
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-c-20 |
(The issue could be found quickly if we add the corresponding tag) According to my understanding to the spec, I think the behavior of clang is correct. Here is the wording http://eel.is/c++draft/dcl.fct.def.coroutine#9:
So the behavior here for foo is, we look up for the name Here is another example: https://godbolt.org/z/1jhKx5dv4 Generally, when we use this functionality, we would use varidic templates to match as many cases as we can. And I guess this is what you want: https://godbolt.org/z/WbW6rYe7a |
Interesting... I think the standard is ambigous in that point.
this condition is clearly fulfilled
The "Otherwise" is not fulfilled because the "if" case's condition was already fulfilled. Or in code (without the ambiguity of human language): My interpretation of the C++ standard is
|
afaict, the current implementation in clang also contradicts the implementation of This implementation uses
with the produce an error if the parameter-less of In particular the following code (see https://godbolt.org/z/Gr8hno358 for a complete example) should not compile, but is still accepted by clang:
|
Oh, my interpretation would be:
The extra So I think it is ambiguous. |
After the consideration, I think the wording could be translated to:
If it is the case, I think the behavior of clang in the first example is correct. And I need to do more reading to be sure whether or not the second example is right... I would try to send this question to WG21. |
There is the related issue: https://cplusplus.github.io/CWG/issues/2585.html It looks like the behavior of clang is wrong indeed. I would try to fix it. |
function in promise_type According to https://cplusplus.github.io/CWG/issues/2585.html, this fixes llvm/llvm-project#54881 Simply, the clang tried to found (do lookup and overload resolution. Is there any better word to use than found?) allocation function in promise_type and global scope. However, this is not consistent with the standard. The standard behavior would be that the compiler shouldn't lookup in global scope in case we lookup the allocation function name in promise_type. In other words, the program is ill-formed if there is incompatible allocation function in promise type. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D125517
Expected behavior
clang should reject the code
because the
operator new
cannot be called forfoo()
.Both MSVC and gcc reject it. gcc provides the error message:
Full example: https://godbolt.org/z/a89vjc77Y
Observed behavior
clang accepts the code, and calls the global
::operator new
instead of the user-provided overloadThe text was updated successfully, but these errors were encountered: