<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54881>54881</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Coroutine ignores overloaded `operator new`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vogelsgesang
</td>
</tr>
</table>
<pre>
## Expected behavior
clang should reject the code
```
#include<coroutine>
struct resumable {
struct promise_type;
using coro_handle = std::coroutine_handle<promise_type>;
resumable(coro_handle handle) : handle_(handle) {}
resumable(resumable&) = delete;
~resumable() { if (handle_) { handle_.destroy(); } }
coro_handle handle_;
};
struct Allocator;
struct resumable::promise_type {
void* operator new(std::size_t sz, Allocator&);
std::coroutine_handle<promise_type> get_return_object() { return std::coroutine_handle<promise_type>::from_promise(*this); }
auto initial_suspend() { return std::suspend_always(); }
auto final_suspend() noexcept { return std::suspend_always(); }
void unhandled_exception() {}
void return_void() {};
};
resumable foo() {
co_return;
}
```
because the `operator new` cannot be called for `foo()`.
Both MSVC and gcc reject it. gcc provides the error message:
```
<source>:26:11: error: 'operator new' is provided by 'std::__n4861::__coroutine_traits_impl<resumable, void>::promise_type' {aka 'resumable::promise_type'} but is not usable with the function signature 'resumable foo()'
26 | resumable foo() {
| ^~~
```
**Full example**: https://godbolt.org/z/a89vjc77Y
## Observed behavior
clang accepts the code, and calls the global `::operator new` instead of the user-provided overload
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVcmO4zYQ_Rr5QsSQJVu2Dzq4vdyCHAIEyEmgxJLMCU0aXNzt-foUqX3c08HEIGSRVXxVrPdYKhV75lGS4iDnjztUFhgp4UofXOkoPkXxoX1WgsqGmKtyghEN39CT2CuQSjHo_LK4G-00SbmshENzeqyUVs5yie_nKaqx2iGQBuNutBRAou1bayGEdMa7VjduoLDPO24fzc5wzMgjF1cqmd-cnnATi9IDjiFkZ8Us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