Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Coroutine ignores overloadedoperator new #54881

Closed
Assignees
ChuanqiXu9
Labels
c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"
@vogelsgesang

Description

@vogelsgesang

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

Metadata

Metadata

Assignees

Labels

c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp