2017-03-23 08:33:33 +08:00
// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s -fcxx-exceptions -fexceptions
2015-10-22 14:13:50 +08:00
2016-09-30 05:47:39 +08:00
void no_coroutine_traits_bad_arg_await ( ) {
2016-10-04 08:31:16 +08:00
co_await a ; // expected-error {{include <experimental/coroutine>}}
2016-09-30 05:47:39 +08:00
// expected-error@-1 {{use of undeclared identifier 'a'}}
}
void no_coroutine_traits_bad_arg_yield ( ) {
2016-10-04 08:31:16 +08:00
co_yield a ; // expected-error {{include <experimental/coroutine>}}
2016-09-30 05:47:39 +08:00
// expected-error@-1 {{use of undeclared identifier 'a'}}
}
void no_coroutine_traits_bad_arg_return ( ) {
2016-10-04 08:31:16 +08:00
co_return a ; // expected-error {{include <experimental/coroutine>}}
2016-09-30 05:47:39 +08:00
// expected-error@-1 {{use of undeclared identifier 'a'}}
}
2017-03-09 11:09:43 +08:00
void no_coroutine_traits ( ) {
co_await 4 ; // expected-error {{std::experimental::coroutine_traits type was not found; include <experimental/coroutine>}}
}
namespace std {
namespace experimental {
template < typename . . . T >
struct coroutine_traits ; // expected-note {{declared here}}
} } // namespace std::experimental
template < typename Promise > struct coro { } ;
template < typename Promise , typename . . . Ps >
struct std : : experimental : : coroutine_traits < coro < Promise > , Ps . . . > {
using promise_type = Promise ;
} ;
2016-09-30 05:47:39 +08:00
2015-10-27 14:02:45 +08:00
struct awaitable {
bool await_ready ( ) ;
2017-03-09 11:09:43 +08:00
template < typename F > void await_suspend ( F ) ;
2015-10-27 14:02:45 +08:00
void await_resume ( ) ;
} a ;
2015-11-24 10:34:39 +08:00
struct suspend_always {
bool await_ready ( ) { return false ; }
2017-03-09 11:09:43 +08:00
template < typename F > void await_suspend ( F ) ;
2015-11-24 10:34:39 +08:00
void await_resume ( ) { }
} ;
struct suspend_never {
bool await_ready ( ) { return true ; }
2017-03-09 11:09:43 +08:00
template < typename F > void await_suspend ( F ) ;
2015-11-24 10:34:39 +08:00
void await_resume ( ) { }
} ;
2015-10-27 14:02:45 +08:00
void no_specialization ( ) {
2016-10-04 08:31:16 +08:00
co_await a ; // expected-error {{implicit instantiation of undefined template 'std::experimental::coroutine_traits<void>'}}
2015-10-27 14:02:45 +08:00
}
2016-10-04 08:31:16 +08:00
template < typename . . . T >
struct std : : experimental : : coroutine_traits < int , T . . . > { } ;
2015-10-27 14:02:45 +08:00
2017-03-07 06:52:28 +08:00
int no_promise_type ( ) { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<int>' has no member named 'promise_type'}}
co_await a ;
2015-11-19 10:36:35 +08:00
}
2016-10-04 08:31:16 +08:00
template < >
struct std : : experimental : : coroutine_traits < double , double > { typedef int promise_type ; } ;
2017-03-07 06:52:28 +08:00
double bad_promise_type ( double ) { // expected-error {{this function cannot be a coroutine: 'experimental::coroutine_traits<double, double>::promise_type' (aka 'int') is not a class}}
co_await a ;
2015-10-27 14:02:45 +08:00
}
2016-10-04 08:31:16 +08:00
template < >
struct std : : experimental : : coroutine_traits < double , int > {
2015-11-21 06:40:06 +08:00
struct promise_type { } ;
} ;
2017-03-07 07:38:15 +08:00
double bad_promise_type_2 ( int ) { // expected-error {{no member named 'initial_suspend'}}
2016-10-04 08:31:16 +08:00
co_yield 0 ; // expected-error {{no member named 'yield_value' in 'std::experimental::coroutine_traits<double, int>::promise_type'}}
2015-11-21 06:40:06 +08:00
}
2017-03-07 06:52:28 +08:00
struct promise ; // expected-note {{forward declaration}}
2016-10-07 05:23:38 +08:00
struct promise_void ;
struct void_tag { } ;
2016-10-04 08:31:16 +08:00
template < typename . . . T >
struct std : : experimental : : coroutine_traits < void , T . . . > { using promise_type = promise ; } ;
2016-10-07 05:23:38 +08:00
template < typename . . . T >
struct std : : experimental : : coroutine_traits < void , void_tag , T . . . >
{ using promise_type = promise_void ; } ;
2016-10-04 08:31:16 +08:00
2017-03-07 07:38:15 +08:00
// FIXME: This diagnostic is terrible.
2017-03-07 06:52:28 +08:00
void undefined_promise ( ) { // expected-error {{this function cannot be a coroutine: 'experimental::coroutine_traits<void>::promise_type' (aka 'promise') is an incomplete type}}
2015-10-27 14:02:45 +08:00
co_await a ;
}
2015-11-21 06:47:10 +08:00
struct yielded_thing { const char * p ; short a , b ; } ;
2015-11-21 06:40:06 +08:00
2015-11-22 10:57:17 +08:00
struct not_awaitable { } ;
2015-11-21 06:40:06 +08:00
struct promise {
2015-11-24 10:34:39 +08:00
void get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
2015-11-22 15:33:28 +08:00
awaitable yield_value ( int ) ; // expected-note 2{{candidate}}
awaitable yield_value ( yielded_thing ) ; // expected-note 2{{candidate}}
not_awaitable yield_value ( void ( ) ) ; // expected-note 2{{candidate}}
void return_value ( int ) ; // expected-note 2{{here}}
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2015-11-21 06:40:06 +08:00
} ;
2016-10-07 05:23:38 +08:00
struct promise_void {
void get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void return_void ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2016-10-07 05:23:38 +08:00
} ;
2017-03-09 11:09:43 +08:00
void no_coroutine_handle ( ) { // expected-error {{std::experimental::coroutine_handle type was not found; include <experimental/coroutine> before defining a coroutine}}
//expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}}
co_return 5 ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
namespace std {
namespace experimental {
template < class PromiseType = void >
struct coroutine_handle {
static coroutine_handle from_address ( void * ) ;
} ;
template < >
struct coroutine_handle < void > {
template < class PromiseType >
coroutine_handle ( coroutine_handle < PromiseType > ) ;
static coroutine_handle from_address ( void * ) ;
} ;
} } // namespace std::experimental
2015-11-21 06:40:06 +08:00
void yield ( ) {
co_yield 0 ;
2015-11-21 06:47:10 +08:00
co_yield { " foo " , 1 , 2 } ;
co_yield { 1e100 } ; // expected-error {{cannot be narrowed}} expected-note {{explicit cast}} expected-warning {{changes value}} expected-warning {{braces around scalar}}
co_yield { " foo " , __LONG_LONG_MAX__ } ; // expected-error {{cannot be narrowed}} expected-note {{explicit cast}} expected-warning {{changes value}}
co_yield { " foo " } ;
2015-11-21 06:40:06 +08:00
co_yield " foo " ; // expected-error {{no matching}}
2015-11-22 10:57:17 +08:00
co_yield 1.0 ;
co_yield yield ; // expected-error {{no member named 'await_ready' in 'not_awaitable'}}
2015-11-21 06:40:06 +08:00
}
2015-10-27 14:02:45 +08:00
2015-11-22 15:05:16 +08:00
void coreturn ( int n ) {
co_await a ;
if ( n = = 0 )
co_return 3 ;
if ( n = = 1 )
2016-10-07 05:23:38 +08:00
co_return { 4 } ; // expected-warning {{braces around scalar initializer}}
2015-11-22 15:05:16 +08:00
if ( n = = 2 )
co_return " foo " ; // expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char [4]'}}
2016-10-07 05:23:38 +08:00
co_return 42 ;
2015-11-22 15:05:16 +08:00
}
2017-03-09 13:01:31 +08:00
template < class T >
void co_await_non_dependent_arg ( T ) {
co_await a ;
}
template void co_await_non_dependent_arg ( int ) ;
2015-10-22 14:13:50 +08:00
void mixed_yield ( ) {
2015-10-27 14:02:45 +08:00
co_yield 0 ; // expected-note {{use of 'co_yield'}}
return ; // expected-error {{not allowed in coroutine}}
2015-10-22 14:13:50 +08:00
}
2017-03-11 10:35:37 +08:00
void mixed_yield_invalid ( ) {
co_yield blah ; // expected-error {{use of undeclared identifier}}
// expected-note@-1 {{function is a coroutine due to use of 'co_yield'}}
return ; // expected-error {{return statement not allowed in coroutine}}
}
template < class T >
void mixed_yield_template ( T ) {
co_yield blah ; // expected-error {{use of undeclared identifier}}
// expected-note@-1 {{function is a coroutine due to use of 'co_yield'}}
return ; // expected-error {{return statement not allowed in coroutine}}
}
template < class T >
void mixed_yield_template2 ( T ) {
co_yield 42 ;
// expected-note@-1 {{function is a coroutine due to use of 'co_yield'}}
return ; // expected-error {{return statement not allowed in coroutine}}
}
template < class T >
void mixed_yield_template3 ( T v ) {
co_yield blah ( v ) ;
// expected-note@-1 {{function is a coroutine due to use of 'co_yield'}}
return ; // expected-error {{return statement not allowed in coroutine}}
}
2015-10-22 14:13:50 +08:00
void mixed_await ( ) {
2015-10-27 14:02:45 +08:00
co_await a ; // expected-note {{use of 'co_await'}}
return ; // expected-error {{not allowed in coroutine}}
2015-10-22 14:13:50 +08:00
}
2017-03-11 10:35:37 +08:00
void mixed_await_invalid ( ) {
co_await 42 ; // expected-error {{'int' is not a structure or union}}
// expected-note@-1 {{function is a coroutine due to use of 'co_await'}}
return ; // expected-error {{not allowed in coroutine}}
}
template < class T >
void mixed_await_template ( T ) {
co_await 42 ;
// expected-note@-1 {{function is a coroutine due to use of 'co_await'}}
return ; // expected-error {{not allowed in coroutine}}
}
template < class T >
void mixed_await_template2 ( T v ) {
co_await v ; // expected-error {{'long' is not a structure or union}}
// expected-note@-1 {{function is a coroutine due to use of 'co_await'}}
return ; // expected-error {{not allowed in coroutine}}
}
template void mixed_await_template2 ( long ) ; // expected-note {{requested here}}
2016-10-07 05:23:38 +08:00
void only_coreturn ( void_tag ) {
2017-01-10 08:08:31 +08:00
co_return ; // OK
2015-10-22 14:13:50 +08:00
}
2016-10-07 05:23:38 +08:00
void mixed_coreturn ( void_tag , bool b ) {
2015-10-22 14:13:50 +08:00
if ( b )
2015-10-27 14:02:45 +08:00
co_return ; // expected-note {{use of 'co_return'}}
2015-10-22 14:13:50 +08:00
else
2015-10-27 14:02:45 +08:00
return ; // expected-error {{not allowed in coroutine}}
2015-10-22 14:13:50 +08:00
}
2017-03-11 10:35:37 +08:00
void mixed_coreturn_invalid ( bool b ) {
if ( b )
co_return ; // expected-note {{use of 'co_return'}}
// expected-error@-1 {{no member named 'return_void' in 'promise'}}
else
return ; // expected-error {{not allowed in coroutine}}
}
template < class T >
void mixed_coreturn_template ( void_tag , bool b , T v ) {
if ( b )
co_return v ; // expected-note {{use of 'co_return'}}
// expected-error@-1 {{no member named 'return_value' in 'promise_void'}}
else
return ; // expected-error {{not allowed in coroutine}}
}
template void mixed_coreturn_template ( void_tag , bool , int ) ; // expected-note {{requested here}}
template < class T >
void mixed_coreturn_template2 ( bool b , T ) {
if ( b )
co_return v ; // expected-note {{use of 'co_return'}}
// expected-error@-1 {{use of undeclared identifier 'v'}}
else
return ; // expected-error {{not allowed in coroutine}}
}
2015-10-22 14:13:50 +08:00
struct CtorDtor {
CtorDtor ( ) {
co_yield 0 ; // expected-error {{'co_yield' cannot be used in a constructor}}
}
2015-10-27 14:02:45 +08:00
CtorDtor ( awaitable a ) {
2015-10-22 14:13:50 +08:00
// The spec doesn't say this is ill-formed, but it must be.
2015-10-27 14:02:45 +08:00
co_await a ; // expected-error {{'co_await' cannot be used in a constructor}}
2015-10-22 14:13:50 +08:00
}
~ CtorDtor ( ) {
co_return 0 ; // expected-error {{'co_return' cannot be used in a destructor}}
}
// FIXME: The spec says this is ill-formed.
void operator = ( CtorDtor & ) {
2016-10-28 02:43:28 +08:00
co_yield 0 ; // expected-error {{'co_yield' cannot be used in a copy assignment operator}}
}
void operator = ( CtorDtor const & ) {
co_yield 0 ; // expected-error {{'co_yield' cannot be used in a copy assignment operator}}
}
void operator = ( CtorDtor & & ) {
co_await a ; // expected-error {{'co_await' cannot be used in a move assignment operator}}
}
void operator = ( CtorDtor const & & ) {
co_await a ; // expected-error {{'co_await' cannot be used in a move assignment operator}}
}
void operator = ( int ) {
co_await a ; // OK. Not a special member
2015-10-22 14:13:50 +08:00
}
} ;
2015-11-20 10:54:01 +08:00
void unevaluated ( ) {
decltype ( co_await a ) ; // expected-error {{cannot be used in an unevaluated context}}
sizeof ( co_await a ) ; // expected-error {{cannot be used in an unevaluated context}}
typeid ( co_await a ) ; // expected-error {{cannot be used in an unevaluated context}}
decltype ( co_yield a ) ; // expected-error {{cannot be used in an unevaluated context}}
sizeof ( co_yield a ) ; // expected-error {{cannot be used in an unevaluated context}}
typeid ( co_yield a ) ; // expected-error {{cannot be used in an unevaluated context}}
}
2016-10-28 02:43:28 +08:00
constexpr auto constexpr_deduced_return_coroutine ( ) {
2015-11-20 10:54:01 +08:00
co_yield 0 ; // expected-error {{'co_yield' cannot be used in a constexpr function}}
2016-10-28 02:43:28 +08:00
// expected-error@-1 {{'co_yield' cannot be used in a function with a deduced return type}}
2015-10-22 14:13:50 +08:00
}
void varargs_coroutine ( const char * , . . . ) {
2015-10-27 14:02:45 +08:00
co_await a ; // expected-error {{'co_await' cannot be used in a varargs function}}
}
2016-10-28 02:43:28 +08:00
auto deduced_return_coroutine ( ) {
co_await a ; // expected-error {{'co_await' cannot be used in a function with a deduced return type}}
}
2015-10-27 14:02:45 +08:00
struct outer { } ;
2017-03-07 07:38:15 +08:00
struct await_arg_1 { } ;
struct await_arg_2 { } ;
namespace adl_ns {
struct coawait_arg_type { } ;
awaitable operator co_await ( coawait_arg_type ) ;
}
2015-10-27 14:02:45 +08:00
namespace dependent_operator_co_await_lookup {
template < typename T > void await_template ( T t ) {
// no unqualified lookup results
co_await t ; // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::not_awaitable'}}
// expected-error@-1 {{call to function 'operator co_await' that is neither visible in the template definition nor found by argument-dependent lookup}}
} ;
template void await_template ( awaitable ) ;
struct indirectly_awaitable { indirectly_awaitable ( outer ) ; } ;
awaitable operator co_await ( indirectly_awaitable ) ; // expected-note {{should be declared prior to}}
template void await_template ( indirectly_awaitable ) ;
struct not_awaitable { } ;
template void await_template ( not_awaitable ) ; // expected-note {{instantiation}}
template < typename T > void await_template_2 ( T t ) {
// one unqualified lookup result
co_await t ;
} ;
template void await_template ( outer ) ; // expected-note {{instantiation}}
template void await_template_2 ( outer ) ;
2017-03-07 07:38:15 +08:00
struct transform_awaitable { } ;
struct transformed { } ;
struct transform_promise {
typedef transform_awaitable await_arg ;
coro < transform_promise > get_return_object ( ) ;
transformed initial_suspend ( ) ;
: : adl_ns : : coawait_arg_type final_suspend ( ) ;
transformed await_transform ( transform_awaitable ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2017-03-07 07:38:15 +08:00
} ;
template < class AwaitArg >
struct basic_promise {
typedef AwaitArg await_arg ;
coro < basic_promise > get_return_object ( ) ;
awaitable initial_suspend ( ) ;
awaitable final_suspend ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2017-03-07 07:38:15 +08:00
} ;
awaitable operator co_await ( await_arg_1 ) ;
template < typename T , typename U >
coro < T > await_template_3 ( U t ) {
co_await t ;
}
template coro < basic_promise < await_arg_1 > > await_template_3 < basic_promise < await_arg_1 > > ( await_arg_1 ) ;
template < class T , int I = 0 >
struct dependent_member {
coro < T > mem_fn ( ) const {
co_await typename T : : await_arg { } ; // expected-error {{call to function 'operator co_await'}}}
}
template < class U >
coro < T > dep_mem_fn ( U t ) {
co_await t ;
}
} ;
template < >
struct dependent_member < long > {
// FIXME this diagnostic is terrible
coro < transform_promise > mem_fn ( ) const { // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::transformed'}}
// expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}}
// expected-note@+1 {{function is a coroutine due to use of 'co_await' here}}
co_await transform_awaitable { } ;
// expected-error@-1 {{no member named 'await_ready'}}
}
template < class R , class U >
coro < R > dep_mem_fn ( U u ) { co_await u ; }
} ;
awaitable operator co_await ( await_arg_2 ) ; // expected-note {{'operator co_await' should be declared prior to the call site}}
template struct dependent_member < basic_promise < await_arg_1 > , 0 > ;
template struct dependent_member < basic_promise < await_arg_2 > , 0 > ; // expected-note {{in instantiation}}
template < >
coro < transform_promise >
// FIXME this diagnostic is terrible
dependent_member < long > : : dep_mem_fn < transform_promise > ( int ) { // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::transformed'}}
//expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}}
//expected-note@+1 {{function is a coroutine due to use of 'co_await' here}}
co_await transform_awaitable { } ;
// expected-error@-1 {{no member named 'await_ready'}}
}
void operator co_await ( transform_awaitable ) = delete ;
awaitable operator co_await ( transformed ) ;
template coro < transform_promise >
dependent_member < long > : : dep_mem_fn < transform_promise > ( transform_awaitable ) ;
template < >
coro < transform_promise > dependent_member < long > : : dep_mem_fn < transform_promise > ( long ) {
co_await transform_awaitable { } ;
}
template < >
struct dependent_member < int > {
coro < transform_promise > mem_fn ( ) const {
co_await transform_awaitable { } ;
}
} ;
template coro < transform_promise > await_template_3 < transform_promise > ( transform_awaitable ) ;
template struct dependent_member < transform_promise > ;
template coro < transform_promise > dependent_member < transform_promise > : : dep_mem_fn ( transform_awaitable ) ;
2015-10-22 14:13:50 +08:00
}
2015-11-21 06:57:24 +08:00
2015-11-22 15:33:28 +08:00
struct yield_fn_tag { } ;
2016-10-04 08:31:16 +08:00
template < >
struct std : : experimental : : coroutine_traits < void , yield_fn_tag > {
2015-11-22 15:33:28 +08:00
struct promise_type {
// FIXME: add an await_transform overload for functions
awaitable yield_value ( int ( ) ) ;
void return_value ( int ( ) ) ;
2015-11-24 10:34:39 +08:00
suspend_never initial_suspend ( ) ;
suspend_never final_suspend ( ) ;
void get_return_object ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2015-11-22 15:33:28 +08:00
} ;
} ;
2015-11-21 06:57:24 +08:00
namespace placeholder {
2015-11-22 15:33:28 +08:00
awaitable f ( ) , f ( int ) ; // expected-note 4{{possible target}}
int g ( ) , g ( int ) ; // expected-note 2{{candidate}}
2015-11-21 06:57:24 +08:00
void x ( ) {
co_await f ; // expected-error {{reference to overloaded function}}
}
void y ( ) {
2015-11-22 15:33:28 +08:00
co_yield g ; // expected-error {{no matching member function for call to 'yield_value'}}
2015-11-21 06:57:24 +08:00
}
void z ( ) {
co_await a ;
2015-11-22 15:33:28 +08:00
co_return g ; // expected-error {{address of overloaded function 'g' does not match required type 'int'}}
}
void x ( yield_fn_tag ) {
co_await f ; // expected-error {{reference to overloaded function}}
}
void y ( yield_fn_tag ) {
co_yield g ;
}
void z ( yield_fn_tag ) {
co_await a ;
co_return g ;
2015-11-21 06:57:24 +08:00
}
}
2015-11-24 10:34:39 +08:00
struct bad_promise_1 {
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2015-11-24 10:34:39 +08:00
} ;
coro < bad_promise_1 > missing_get_return_object ( ) { // expected-error {{no member named 'get_return_object' in 'bad_promise_1'}}
co_await a ;
}
struct bad_promise_2 {
coro < bad_promise_2 > get_return_object ( ) ;
// FIXME: We shouldn't offer a typo-correction here!
suspend_always final_suspend ( ) ; // expected-note {{here}}
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2015-11-24 10:34:39 +08:00
} ;
2017-03-07 07:38:15 +08:00
// FIXME: This shouldn't happen twice
2015-11-24 10:34:39 +08:00
coro < bad_promise_2 > missing_initial_suspend ( ) { // expected-error {{no member named 'initial_suspend' in 'bad_promise_2'}}
co_await a ;
}
struct bad_promise_3 {
coro < bad_promise_3 > get_return_object ( ) ;
// FIXME: We shouldn't offer a typo-correction here!
suspend_always initial_suspend ( ) ; // expected-note {{here}}
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2015-11-24 10:34:39 +08:00
} ;
coro < bad_promise_3 > missing_final_suspend ( ) { // expected-error {{no member named 'final_suspend' in 'bad_promise_3'}}
co_await a ;
}
struct bad_promise_4 {
coro < bad_promise_4 > get_return_object ( ) ;
not_awaitable initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2015-11-24 10:34:39 +08:00
} ;
// FIXME: This diagnostic is terrible.
coro < bad_promise_4 > bad_initial_suspend ( ) { // expected-error {{no member named 'await_ready' in 'not_awaitable'}}
2017-03-07 07:38:15 +08:00
// expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}}
co_await a ; // expected-note {{function is a coroutine due to use of 'co_await' here}}
2015-11-24 10:34:39 +08:00
}
struct bad_promise_5 {
coro < bad_promise_5 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
not_awaitable final_suspend ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ;
2015-11-24 10:34:39 +08:00
} ;
// FIXME: This diagnostic is terrible.
coro < bad_promise_5 > bad_final_suspend ( ) { // expected-error {{no member named 'await_ready' in 'not_awaitable'}}
2017-03-07 07:38:15 +08:00
// expected-note@-1 {{call to 'final_suspend' implicitly required by the final suspend point}}
co_await a ; // expected-note {{function is a coroutine due to use of 'co_await' here}}
2015-11-24 10:34:39 +08:00
}
2016-10-01 06:38:31 +08:00
2016-10-27 15:30:31 +08:00
struct bad_promise_6 {
coro < bad_promise_6 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-05-25 22:59:39 +08:00
void return_void ( ) ; // expected-note 2 {{member 'return_void' first declared here}}
void return_value ( int ) const ; // expected-note 2 {{member 'return_value' first declared here}}
2016-10-27 15:30:31 +08:00
void return_value ( int ) ;
} ;
coro < bad_promise_6 > bad_implicit_return ( ) { // expected-error {{'bad_promise_6' declares both 'return_value' and 'return_void'}}
co_await a ;
}
2017-04-04 03:21:00 +08:00
template < class T >
coro < T > bad_implicit_return_dependent ( T ) { // expected-error {{'bad_promise_6' declares both 'return_value' and 'return_void'}}
co_await a ;
}
template coro < bad_promise_6 > bad_implicit_return_dependent ( bad_promise_6 ) ; // expected-note {{in instantiation}}
2017-05-24 22:34:19 +08:00
struct bad_promise_7 { // expected-note 2 {{defined here}}
2016-10-27 15:30:31 +08:00
coro < bad_promise_7 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void return_void ( ) ;
} ;
2017-03-23 08:33:33 +08:00
coro < bad_promise_7 > no_unhandled_exception ( ) { // expected-error {{'bad_promise_7' is required to declare the member 'unhandled_exception()'}}
2016-10-27 15:30:31 +08:00
co_await a ;
}
2017-04-04 03:21:00 +08:00
template < class T >
coro < T > no_unhandled_exception_dependent ( T ) { // expected-error {{'bad_promise_7' is required to declare the member 'unhandled_exception()'}}
co_await a ;
}
template coro < bad_promise_7 > no_unhandled_exception_dependent ( bad_promise_7 ) ; // expected-note {{in instantiation}}
2017-03-07 07:38:15 +08:00
struct bad_promise_base {
private :
void return_void ( ) ;
} ;
struct bad_promise_8 : bad_promise_base {
2016-10-27 15:30:31 +08:00
coro < bad_promise_8 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
2017-04-04 03:21:00 +08:00
void unhandled_exception ( ) __attribute__ ( ( unavailable ) ) ; // expected-note 2 {{made unavailable}}
void unhandled_exception ( ) const ; // expected-note 2 {{candidate}}
void unhandled_exception ( void * ) const ; // expected-note 2 {{requires 1 argument, but 0 were provided}}
2016-10-27 15:30:31 +08:00
} ;
2017-03-23 08:33:33 +08:00
coro < bad_promise_8 > calls_unhandled_exception ( ) {
// expected-error@-1 {{call to unavailable member function 'unhandled_exception'}}
2017-03-07 07:38:15 +08:00
// FIXME: also warn about private 'return_void' here. Even though building
2017-03-23 08:33:33 +08:00
// the call to unhandled_exception has already failed.
2016-10-27 15:30:31 +08:00
co_await a ;
}
2016-10-01 06:38:31 +08:00
2017-04-04 03:21:00 +08:00
template < class T >
coro < T > calls_unhandled_exception_dependent ( T ) {
// expected-error@-1 {{call to unavailable member function 'unhandled_exception'}}
co_await a ;
}
template coro < bad_promise_8 > calls_unhandled_exception_dependent ( bad_promise_8 ) ; // expected-note {{in instantiation}}
2017-03-07 07:38:15 +08:00
struct bad_promise_9 {
coro < bad_promise_9 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void await_transform ( void * ) ; // expected-note {{candidate}}
awaitable await_transform ( int ) __attribute__ ( ( unavailable ) ) ; // expected-note {{explicitly made unavailable}}
void return_void ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-03-07 07:38:15 +08:00
} ;
coro < bad_promise_9 > calls_await_transform ( ) {
co_await 42 ; // expected-error {{call to unavailable member function 'await_transform'}}
// expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}}
}
struct bad_promise_10 {
coro < bad_promise_10 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
int await_transform ;
void return_void ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-03-07 07:38:15 +08:00
} ;
coro < bad_promise_10 > bad_coawait ( ) {
// FIXME this diagnostic is terrible
co_await 42 ; // expected-error {{called object type 'int' is not a function or function pointer}}
// expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}}
}
struct call_operator {
template < class . . . Args >
awaitable operator ( ) ( Args . . . ) const { return a ; }
} ;
void ret_void ( ) ;
struct good_promise_1 {
coro < good_promise_1 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-03-07 07:38:15 +08:00
static const call_operator await_transform ;
using Fn = void ( * ) ( ) ;
Fn return_void = ret_void ;
} ;
const call_operator good_promise_1 : : await_transform ;
coro < good_promise_1 > ok_static_coawait ( ) {
// FIXME this diagnostic is terrible
co_await 42 ;
}
2016-10-04 08:31:16 +08:00
template < > struct std : : experimental : : coroutine_traits < int , int , const char * * >
2016-10-01 06:38:31 +08:00
{ using promise_type = promise ; } ;
2016-10-28 02:43:28 +08:00
int main ( int , const char * * ) {
co_await a ; // expected-error {{'co_await' cannot be used in the 'main' function}}
2016-10-01 06:38:31 +08:00
}
2017-03-09 11:09:43 +08:00
struct good_promise_2 {
float get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void return_void ( ) ;
2017-03-23 08:33:33 +08:00
void unhandled_exception ( ) ;
2017-03-09 11:09:43 +08:00
} ;
template < > struct std : : experimental : : coroutine_handle < good_promise_2 > { } ;
template < > struct std : : experimental : : coroutine_traits < float >
{ using promise_type = good_promise_2 ; } ;
float badly_specialized_coro_handle ( ) { // expected-error {{std::experimental::coroutine_handle missing a member named 'from_address'}}
//expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}}
co_return ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
2017-03-28 07:36:59 +08:00
2017-04-18 11:12:48 +08:00
namespace std {
struct nothrow_t { } ;
constexpr nothrow_t nothrow = { } ;
}
using SizeT = decltype ( sizeof ( int ) ) ;
void * operator new ( SizeT __sz , const std : : nothrow_t & ) noexcept ;
void operator delete ( void * __p , const std : : nothrow_t & ) noexcept ;
2017-03-28 07:36:59 +08:00
struct promise_on_alloc_failure_tag { } ;
template < >
struct std : : experimental : : coroutine_traits < int , promise_on_alloc_failure_tag > {
struct promise_type {
int get_return_object ( ) { }
suspend_always initial_suspend ( ) { return { } ; }
suspend_always final_suspend ( ) { return { } ; }
void return_void ( ) { }
int get_return_object_on_allocation_failure ( ) ; // expected-error{{'promise_type': 'get_return_object_on_allocation_failure()' must be a static member function}}
void unhandled_exception ( ) ;
} ;
} ;
extern " C " int f ( promise_on_alloc_failure_tag ) {
co_return ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
2017-04-04 03:21:00 +08:00
struct bad_promise_11 {
coro < bad_promise_11 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void unhandled_exception ( ) ;
void return_void ( ) ;
private :
static coro < bad_promise_11 > get_return_object_on_allocation_failure ( ) ; // expected-note 2 {{declared private here}}
} ;
coro < bad_promise_11 > private_alloc_failure_handler ( ) {
// expected-error@-1 {{'get_return_object_on_allocation_failure' is a private member of 'bad_promise_11'}}
co_return ; // FIXME: Add a "declared coroutine here" note.
}
template < class T >
coro < T > dependent_private_alloc_failure_handler ( T ) {
// expected-error@-1 {{'get_return_object_on_allocation_failure' is a private member of 'bad_promise_11'}}
co_return ; // FIXME: Add a "declared coroutine here" note.
}
template coro < bad_promise_11 > dependent_private_alloc_failure_handler ( bad_promise_11 ) ;
// expected-note@-1 {{requested here}}
2017-04-18 11:12:48 +08:00
struct bad_promise_12 {
coro < bad_promise_12 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void unhandled_exception ( ) ;
void return_void ( ) ;
static coro < bad_promise_12 > get_return_object_on_allocation_failure ( ) ;
static void * operator new ( SizeT ) ;
// expected-error@-1 2 {{'operator new' is required to have a non-throwing noexcept specification when the promise type declares 'get_return_object_on_allocation_failure()'}}
} ;
coro < bad_promise_12 > throwing_in_class_new ( ) { // expected-note {{call to 'operator new' implicitly required by coroutine function here}}
co_return ;
}
template < class T >
coro < T > dependent_throwing_in_class_new ( T ) { // expected-note {{call to 'operator new' implicitly required by coroutine function here}}
co_return ;
}
template coro < bad_promise_12 > dependent_throwing_in_class_new ( bad_promise_12 ) ; // expected-note {{requested here}}
struct good_promise_13 {
coro < good_promise_13 > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void unhandled_exception ( ) ;
void return_void ( ) ;
static coro < good_promise_13 > get_return_object_on_allocation_failure ( ) ;
} ;
coro < good_promise_13 > uses_nothrow_new ( ) {
co_return ;
}
template < class T >
coro < T > dependent_uses_nothrow_new ( T ) {
co_return ;
}
template coro < good_promise_13 > dependent_uses_nothrow_new ( good_promise_13 ) ;
2017-05-23 04:22:23 +08:00
struct mismatch_gro_type_tag1 { } ;
template < >
struct std : : experimental : : coroutine_traits < int , mismatch_gro_type_tag1 > {
struct promise_type {
2017-05-25 22:59:39 +08:00
void get_return_object ( ) { } //expected-note {{member 'get_return_object' declared here}}
2017-05-23 04:22:23 +08:00
suspend_always initial_suspend ( ) { return { } ; }
suspend_always final_suspend ( ) { return { } ; }
void return_void ( ) { }
void unhandled_exception ( ) ;
} ;
} ;
extern " C " int f ( mismatch_gro_type_tag1 ) {
// expected-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'void'}}
co_return ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
struct mismatch_gro_type_tag2 { } ;
template < >
struct std : : experimental : : coroutine_traits < int , mismatch_gro_type_tag2 > {
struct promise_type {
2017-05-25 22:59:39 +08:00
void * get_return_object ( ) { } //expected-note {{member 'get_return_object' declared here}}
2017-05-23 04:22:23 +08:00
suspend_always initial_suspend ( ) { return { } ; }
suspend_always final_suspend ( ) { return { } ; }
void return_void ( ) { }
void unhandled_exception ( ) ;
} ;
} ;
extern " C " int f ( mismatch_gro_type_tag2 ) {
// expected-error@-1 {{cannot initialize return object of type 'int' with an lvalue of type 'void *'}}
co_return ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
struct mismatch_gro_type_tag3 { } ;
template < >
struct std : : experimental : : coroutine_traits < int , mismatch_gro_type_tag3 > {
struct promise_type {
int get_return_object ( ) { }
2017-05-25 22:59:39 +08:00
static void get_return_object_on_allocation_failure ( ) { } //expected-note {{member 'get_return_object_on_allocation_failure' declared here}}
2017-05-23 04:22:23 +08:00
suspend_always initial_suspend ( ) { return { } ; }
suspend_always final_suspend ( ) { return { } ; }
void return_void ( ) { }
void unhandled_exception ( ) ;
} ;
} ;
extern " C " int f ( mismatch_gro_type_tag3 ) {
// expected-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'void'}}
co_return ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
struct mismatch_gro_type_tag4 { } ;
template < >
struct std : : experimental : : coroutine_traits < int , mismatch_gro_type_tag4 > {
struct promise_type {
int get_return_object ( ) { }
2017-05-25 22:59:39 +08:00
static char * get_return_object_on_allocation_failure ( ) { } //expected-note {{member 'get_return_object_on_allocation_failure' declared}}
2017-05-23 04:22:23 +08:00
suspend_always initial_suspend ( ) { return { } ; }
suspend_always final_suspend ( ) { return { } ; }
void return_void ( ) { }
void unhandled_exception ( ) ;
} ;
} ;
extern " C " int f ( mismatch_gro_type_tag4 ) {
// expected-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'char *'}}
co_return ; //expected-note {{function is a coroutine due to use of 'co_return' here}}
}
2017-05-25 22:59:39 +08:00
struct bad_promise_no_return_func { // expected-note {{'bad_promise_no_return_func' defined here}}
2017-05-25 10:16:53 +08:00
coro < bad_promise_no_return_func > get_return_object ( ) ;
suspend_always initial_suspend ( ) ;
suspend_always final_suspend ( ) ;
void unhandled_exception ( ) ;
} ;
2017-05-25 22:59:39 +08:00
// FIXME: The PDTS currently specifies this as UB, technically forbidding a
// diagnostic.
2017-05-25 10:16:53 +08:00
coro < bad_promise_no_return_func > no_return_value_or_return_void ( ) {
2017-05-25 22:59:39 +08:00
// expected-error@-1 {{'bad_promise_no_return_func' must declare either 'return_value' or 'return_void'}}
2017-05-25 10:16:53 +08:00
co_await a ;
}
2017-05-29 02:21:12 +08:00
struct bad_await_suspend_return {
bool await_ready ( ) ;
2017-06-01 07:41:11 +08:00
// expected-error@+1 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'char')}}
2017-05-29 02:21:12 +08:00
char await_suspend ( std : : experimental : : coroutine_handle < > ) ;
void await_resume ( ) ;
} ;
struct bad_await_ready_return {
2017-06-01 07:41:11 +08:00
// expected-note@+1 {{return type of 'await_ready' is required to be contextually convertible to 'bool'}}
2017-05-29 02:21:12 +08:00
void await_ready ( ) ;
bool await_suspend ( std : : experimental : : coroutine_handle < > ) ;
void await_resume ( ) ;
} ;
struct await_ready_explicit_bool {
struct BoolT {
explicit operator bool ( ) const ;
} ;
BoolT await_ready ( ) ;
void await_suspend ( std : : experimental : : coroutine_handle < > ) ;
void await_resume ( ) ;
} ;
2017-06-01 07:41:11 +08:00
template < class SuspendTy >
struct await_suspend_type_test {
bool await_ready ( ) ;
// expected-error@+2 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'bool &')}}
// expected-error@+1 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'bool &&')}}
SuspendTy await_suspend ( std : : experimental : : coroutine_handle < > ) ;
void await_resume ( ) ;
} ;
2017-05-29 02:21:12 +08:00
void test_bad_suspend ( ) {
{
// FIXME: The actual error emitted here is terrible, and no number of notes can save it.
bad_await_ready_return a ;
// expected-error@+1 {{value of type 'void' is not contextually convertible to 'bool'}}
co_await a ; // expected-note {{call to 'await_ready' implicitly required by coroutine function here}}
}
{
bad_await_suspend_return b ;
co_await b ; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}}
}
{
await_ready_explicit_bool c ;
co_await c ; // OK
}
2017-06-01 07:41:11 +08:00
{
await_suspend_type_test < bool & & > a ;
await_suspend_type_test < bool & > b ;
await_suspend_type_test < const void > c ;
await_suspend_type_test < const volatile bool > d ;
co_await a ; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}}
co_await b ; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}}
co_await c ; // OK
co_await d ; // OK
}
2017-05-29 02:21:12 +08:00
}
2017-06-03 08:22:18 +08:00
template < int ID = 0 >
struct NoCopy {
NoCopy ( NoCopy const & ) = delete ; // expected-note 2 {{deleted here}}
} ;
template < class T , class U >
void test_dependent_param ( T t , U ) {
// expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}}
// expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}}
( ( void ) t ) ;
co_return 42 ;
}
template void test_dependent_param ( NoCopy < 0 > , NoCopy < 1 > ) ; // expected-note {{requested here}}