1 // RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify
2 #include "Inputs/std-coroutine.h"
5 typedef decltype(sizeof(int)) size_t;
12 void *operator new(std::size_t sz
, Allocator
&);
14 resumable
get_return_object() { return {}; }
15 auto initial_suspend() { return std::suspend_always(); }
16 auto final_suspend() noexcept
{ return std::suspend_always(); }
17 void unhandled_exception() {}
22 resumable
f1() { // expected-error {{'operator new' provided by 'std::coroutine_traits<resumable>::promise_type' (aka 'resumable::promise_type') is not usable with the function signature of 'f1'}}
26 // NOTE: Although the argument here is a rvalue reference and the corresponding
27 // allocation function in resumable::promise_type have lvalue references, it looks
28 // the signature of f2 is invalid. But according to [dcl.fct.def.coroutine]p4:
30 // In the following, pi is an lvalue of type Pi, where p1 denotes the object
31 // parameter and pi+1 denotes the ith non-object function parameter for a
32 // non-static member function.
34 // And [dcl.fct.def.coroutine]p9.1
36 // overload resolution is performed on a function call created by assembling an argument list.
37 // The first argument is the amount of space requested, and has type std::size_t.
38 // The lvalues p1…pn are the succeeding arguments.
40 // So the actual type passed to resumable::promise_type::operator new is lvalue
41 // Allocator. It is allowed to convert a lvalue to a lvalue reference. So the
42 // following one is valid.
43 resumable
f2(Allocator
&&) {
47 resumable
f3(Allocator
&) {
51 resumable
f4(Allocator
) {
55 resumable
f5(const Allocator
) { // expected-error {{operator new' provided by 'std::coroutine_traits<resumable, const Allocator>::promise_type' (aka 'resumable::promise_type') is not usable}}
59 resumable
f6(const Allocator
&) { // expected-error {{operator new' provided by 'std::coroutine_traits<resumable, const Allocator &>::promise_type' (aka 'resumable::promise_type') is not usable}}
63 struct promise_base1
{
64 void *operator new(std::size_t sz
); // expected-note {{member found by ambiguous name lookup}}
67 struct promise_base2
{
68 void *operator new(std::size_t sz
); // expected-note {{member found by ambiguous name lookup}}
72 struct promise_type
: public promise_base1
, public promise_base2
{
73 resumable2
get_return_object() { return {}; }
74 auto initial_suspend() { return std::suspend_always(); }
75 auto final_suspend() noexcept
{ return std::suspend_always(); }
76 void unhandled_exception() {}
81 resumable2
f7() { // expected-error {{member 'operator new' found in multiple base classes of different types}}