- Notifications
You must be signed in to change notification settings - Fork14.5k
Closed
Description
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 theoperator new
cannot be called forfoo()
.
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