| Gor Nishanov | bbe1c07 | 2017-02-13 05:05:02 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s -fcxx-exceptions |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 2 | |
| Eric Fiselier | a546528 | 2016-09-29 21:47:39 +0000 | [diff] [blame] | 3 | void no_coroutine_traits_bad_arg_await() { |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 4 | co_await a; // expected-error {{include <experimental/coroutine>}} |
| Eric Fiselier | a546528 | 2016-09-29 21:47:39 +0000 | [diff] [blame] | 5 | // expected-error@-1 {{use of undeclared identifier 'a'}} |
| 6 | } |
| 7 | |
| 8 | void no_coroutine_traits_bad_arg_yield() { |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 9 | co_yield a; // expected-error {{include <experimental/coroutine>}} |
| Eric Fiselier | a546528 | 2016-09-29 21:47:39 +0000 | [diff] [blame] | 10 | // expected-error@-1 {{use of undeclared identifier 'a'}} |
| 11 | } |
| 12 | |
| 13 | |
| 14 | void no_coroutine_traits_bad_arg_return() { |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 15 | co_return a; // expected-error {{include <experimental/coroutine>}} |
| Eric Fiselier | a546528 | 2016-09-29 21:47:39 +0000 | [diff] [blame] | 16 | // expected-error@-1 {{use of undeclared identifier 'a'}} |
| 17 | } |
| 18 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 19 | void no_coroutine_traits() { |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 20 | co_await 4; // expected-error {{std::experimental::coroutine_traits type was not found; include <experimental/coroutine>}} |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | namespace std { |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 24 | namespace experimental { |
| 25 | template <typename... T> |
| 26 | struct coroutine_traits; // expected-note {{declared here}} |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 27 | }} // namespace std::experimental |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 28 | |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 29 | template<typename Promise> struct coro {}; |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 30 | template <typename Promise, typename... Ps> |
| 31 | struct std::experimental::coroutine_traits<coro<Promise>, Ps...> { |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 32 | using promise_type = Promise; |
| 33 | }; |
| 34 | |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 35 | struct awaitable { |
| 36 | bool await_ready(); |
| 37 | template <typename F> void await_suspend(F); |
| 38 | void await_resume(); |
| 39 | } a; |
| 40 | |
| 41 | struct suspend_always { |
| 42 | bool await_ready() { return false; } |
| 43 | template <typename F> void await_suspend(F); |
| 44 | void await_resume() {} |
| 45 | }; |
| 46 | |
| 47 | struct suspend_never { |
| 48 | bool await_ready() { return true; } |
| 49 | template <typename F> void await_suspend(F); |
| 50 | void await_resume() {} |
| 51 | }; |
| 52 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 53 | void no_specialization() { |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 54 | co_await a; // expected-error {{implicit instantiation of undefined template 'std::experimental::coroutine_traits<void>'}} |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 57 | template <typename... T> |
| 58 | struct std::experimental::coroutine_traits<int, T...> {}; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 59 | |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 60 | int no_promise_type() { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<int>' has no member named 'promise_type'}} |
| 61 | co_await a; |
| Richard Smith | 9b2f53e | 2015-11-19 02:36:35 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 64 | template <> |
| 65 | struct std::experimental::coroutine_traits<double, double> { typedef int promise_type; }; |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 66 | 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}} |
| 67 | co_await a; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 70 | template <> |
| 71 | struct std::experimental::coroutine_traits<double, int> { |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 72 | struct promise_type {}; |
| 73 | }; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 74 | double bad_promise_type_2(int) { // expected-error {{no member named 'initial_suspend'}} |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 75 | co_yield 0; // expected-error {{no member named 'yield_value' in 'std::experimental::coroutine_traits<double, int>::promise_type'}} |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 78 | struct promise; // expected-note {{forward declaration}} |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 79 | struct promise_void; |
| 80 | struct void_tag {}; |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 81 | template <typename... T> |
| 82 | struct std::experimental::coroutine_traits<void, T...> { using promise_type = promise; }; |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 83 | template <typename... T> |
| 84 | struct std::experimental::coroutine_traits<void, void_tag, T...> |
| 85 | { using promise_type = promise_void; }; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 86 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 87 | // FIXME: This diagnostic is terrible. |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 88 | void undefined_promise() { // expected-error {{this function cannot be a coroutine: 'experimental::coroutine_traits<void>::promise_type' (aka 'promise') is an incomplete type}} |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 89 | co_await a; |
| 90 | } |
| 91 | |
| Richard Smith | ae3d147 | 2015-11-20 22:47:10 +0000 | [diff] [blame] | 92 | struct yielded_thing { const char *p; short a, b; }; |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 93 | |
| Richard Smith | d7bed4d | 2015-11-22 02:57:17 +0000 | [diff] [blame] | 94 | struct not_awaitable {}; |
| 95 | |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 96 | struct promise { |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 97 | void get_return_object(); |
| 98 | suspend_always initial_suspend(); |
| 99 | suspend_always final_suspend(); |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 100 | awaitable yield_value(int); // expected-note 2{{candidate}} |
| 101 | awaitable yield_value(yielded_thing); // expected-note 2{{candidate}} |
| 102 | not_awaitable yield_value(void()); // expected-note 2{{candidate}} |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 103 | void return_value(int); // expected-note 2{{here}} |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 106 | struct promise_void { |
| 107 | void get_return_object(); |
| 108 | suspend_always initial_suspend(); |
| 109 | suspend_always final_suspend(); |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 110 | void return_void(); |
| 111 | }; |
| 112 | |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 113 | void no_coroutine_handle() { // expected-error {{std::experimental::coroutine_handle type was not found; include <experimental/coroutine> before defining a coroutine}} |
| 114 | //expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 115 | co_return 5; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 116 | } |
| 117 | |
| 118 | namespace std { |
| 119 | namespace experimental { |
| 120 | template <class PromiseType = void> |
| 121 | struct coroutine_handle { |
| 122 | static coroutine_handle from_address(void *); |
| 123 | }; |
| 124 | template <> |
| 125 | struct coroutine_handle<void> { |
| 126 | template <class PromiseType> |
| 127 | coroutine_handle(coroutine_handle<PromiseType>); |
| 128 | static coroutine_handle from_address(void *); |
| 129 | }; |
| 130 | }} // namespace std::experimental |
| 131 | |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 132 | void yield() { |
| 133 | co_yield 0; |
| Richard Smith | ae3d147 | 2015-11-20 22:47:10 +0000 | [diff] [blame] | 134 | co_yield {"foo", 1, 2}; |
| 135 | co_yield {1e100}; // expected-error {{cannot be narrowed}} expected-note {{explicit cast}} expected-warning {{changes value}} expected-warning {{braces around scalar}} |
| 136 | co_yield {"foo", __LONG_LONG_MAX__}; // expected-error {{cannot be narrowed}} expected-note {{explicit cast}} expected-warning {{changes value}} |
| 137 | co_yield {"foo"}; |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 138 | co_yield "foo"; // expected-error {{no matching}} |
| Richard Smith | d7bed4d | 2015-11-22 02:57:17 +0000 | [diff] [blame] | 139 | co_yield 1.0; |
| 140 | co_yield yield; // expected-error {{no member named 'await_ready' in 'not_awaitable'}} |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 141 | } |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 142 | |
| Richard Smith | 4ba6660 | 2015-11-22 07:05:16 +0000 | [diff] [blame] | 143 | void coreturn(int n) { |
| 144 | co_await a; |
| 145 | if (n == 0) |
| 146 | co_return 3; |
| 147 | if (n == 1) |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 148 | co_return {4}; // expected-warning {{braces around scalar initializer}} |
| Richard Smith | 4ba6660 | 2015-11-22 07:05:16 +0000 | [diff] [blame] | 149 | if (n == 2) |
| 150 | co_return "foo"; // expected-error {{cannot initialize a parameter of type 'int' with an lvalue of type 'const char [4]'}} |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 151 | co_return 42; |
| Richard Smith | 4ba6660 | 2015-11-22 07:05:16 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| Eric Fiselier | 8d409e8 | 2017-03-09 05:01:31 +0000 | [diff] [blame^] | 154 | template <class T> |
| 155 | void co_await_non_dependent_arg(T) { |
| 156 | co_await a; |
| 157 | } |
| 158 | template void co_await_non_dependent_arg(int); |
| 159 | |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 160 | void mixed_yield() { |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 161 | co_yield 0; // expected-note {{use of 'co_yield'}} |
| 162 | return; // expected-error {{not allowed in coroutine}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void mixed_await() { |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 166 | co_await a; // expected-note {{use of 'co_await'}} |
| 167 | return; // expected-error {{not allowed in coroutine}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 170 | void only_coreturn(void_tag) { |
| Gor Nishanov | d97f6bf | 2017-01-10 00:08:31 +0000 | [diff] [blame] | 171 | co_return; // OK |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 174 | void mixed_coreturn(void_tag, bool b) { |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 175 | if (b) |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 176 | co_return; // expected-note {{use of 'co_return'}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 177 | else |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 178 | return; // expected-error {{not allowed in coroutine}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | struct CtorDtor { |
| 182 | CtorDtor() { |
| 183 | co_yield 0; // expected-error {{'co_yield' cannot be used in a constructor}} |
| 184 | } |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 185 | CtorDtor(awaitable a) { |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 186 | // The spec doesn't say this is ill-formed, but it must be. |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 187 | co_await a; // expected-error {{'co_await' cannot be used in a constructor}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 188 | } |
| 189 | ~CtorDtor() { |
| 190 | co_return 0; // expected-error {{'co_return' cannot be used in a destructor}} |
| 191 | } |
| 192 | // FIXME: The spec says this is ill-formed. |
| 193 | void operator=(CtorDtor&) { |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 194 | co_yield 0; // expected-error {{'co_yield' cannot be used in a copy assignment operator}} |
| 195 | } |
| 196 | void operator=(CtorDtor const &) { |
| 197 | co_yield 0; // expected-error {{'co_yield' cannot be used in a copy assignment operator}} |
| 198 | } |
| 199 | void operator=(CtorDtor &&) { |
| 200 | co_await a; // expected-error {{'co_await' cannot be used in a move assignment operator}} |
| 201 | } |
| 202 | void operator=(CtorDtor const &&) { |
| 203 | co_await a; // expected-error {{'co_await' cannot be used in a move assignment operator}} |
| 204 | } |
| 205 | void operator=(int) { |
| 206 | co_await a; // OK. Not a special member |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 207 | } |
| 208 | }; |
| 209 | |
| Richard Smith | 744b224 | 2015-11-20 02:54:01 +0000 | [diff] [blame] | 210 | void unevaluated() { |
| 211 | decltype(co_await a); // expected-error {{cannot be used in an unevaluated context}} |
| 212 | sizeof(co_await a); // expected-error {{cannot be used in an unevaluated context}} |
| 213 | typeid(co_await a); // expected-error {{cannot be used in an unevaluated context}} |
| 214 | decltype(co_yield a); // expected-error {{cannot be used in an unevaluated context}} |
| 215 | sizeof(co_yield a); // expected-error {{cannot be used in an unevaluated context}} |
| 216 | typeid(co_yield a); // expected-error {{cannot be used in an unevaluated context}} |
| 217 | } |
| 218 | |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 219 | constexpr auto constexpr_deduced_return_coroutine() { |
| Richard Smith | 744b224 | 2015-11-20 02:54:01 +0000 | [diff] [blame] | 220 | co_yield 0; // expected-error {{'co_yield' cannot be used in a constexpr function}} |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 221 | // expected-error@-1 {{'co_yield' cannot be used in a function with a deduced return type}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void varargs_coroutine(const char *, ...) { |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 225 | co_await a; // expected-error {{'co_await' cannot be used in a varargs function}} |
| 226 | } |
| 227 | |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 228 | auto deduced_return_coroutine() { |
| 229 | co_await a; // expected-error {{'co_await' cannot be used in a function with a deduced return type}} |
| 230 | } |
| 231 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 232 | struct outer {}; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 233 | struct await_arg_1 {}; |
| 234 | struct await_arg_2 {}; |
| 235 | |
| 236 | namespace adl_ns { |
| 237 | struct coawait_arg_type {}; |
| 238 | awaitable operator co_await(coawait_arg_type); |
| 239 | } |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 240 | |
| 241 | namespace dependent_operator_co_await_lookup { |
| 242 | template<typename T> void await_template(T t) { |
| 243 | // no unqualified lookup results |
| 244 | co_await t; // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::not_awaitable'}} |
| 245 | // expected-error@-1 {{call to function 'operator co_await' that is neither visible in the template definition nor found by argument-dependent lookup}} |
| 246 | }; |
| 247 | template void await_template(awaitable); |
| 248 | |
| 249 | struct indirectly_awaitable { indirectly_awaitable(outer); }; |
| 250 | awaitable operator co_await(indirectly_awaitable); // expected-note {{should be declared prior to}} |
| 251 | template void await_template(indirectly_awaitable); |
| 252 | |
| 253 | struct not_awaitable {}; |
| 254 | template void await_template(not_awaitable); // expected-note {{instantiation}} |
| 255 | |
| 256 | template<typename T> void await_template_2(T t) { |
| 257 | // one unqualified lookup result |
| 258 | co_await t; |
| 259 | }; |
| 260 | template void await_template(outer); // expected-note {{instantiation}} |
| 261 | template void await_template_2(outer); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 262 | |
| 263 | struct transform_awaitable {}; |
| 264 | struct transformed {}; |
| 265 | |
| 266 | struct transform_promise { |
| 267 | typedef transform_awaitable await_arg; |
| 268 | coro<transform_promise> get_return_object(); |
| 269 | transformed initial_suspend(); |
| 270 | ::adl_ns::coawait_arg_type final_suspend(); |
| 271 | transformed await_transform(transform_awaitable); |
| 272 | }; |
| 273 | template <class AwaitArg> |
| 274 | struct basic_promise { |
| 275 | typedef AwaitArg await_arg; |
| 276 | coro<basic_promise> get_return_object(); |
| 277 | awaitable initial_suspend(); |
| 278 | awaitable final_suspend(); |
| 279 | }; |
| 280 | |
| 281 | awaitable operator co_await(await_arg_1); |
| 282 | |
| 283 | template <typename T, typename U> |
| 284 | coro<T> await_template_3(U t) { |
| 285 | co_await t; |
| 286 | } |
| 287 | |
| 288 | template coro<basic_promise<await_arg_1>> await_template_3<basic_promise<await_arg_1>>(await_arg_1); |
| 289 | |
| 290 | template <class T, int I = 0> |
| 291 | struct dependent_member { |
| 292 | coro<T> mem_fn() const { |
| 293 | co_await typename T::await_arg{}; // expected-error {{call to function 'operator co_await'}}} |
| 294 | } |
| 295 | template <class U> |
| 296 | coro<T> dep_mem_fn(U t) { |
| 297 | co_await t; |
| 298 | } |
| 299 | }; |
| 300 | |
| 301 | template <> |
| 302 | struct dependent_member<long> { |
| 303 | // FIXME this diagnostic is terrible |
| 304 | coro<transform_promise> mem_fn() const { // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::transformed'}} |
| 305 | // expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 306 | // expected-note@+1 {{function is a coroutine due to use of 'co_await' here}} |
| 307 | co_await transform_awaitable{}; |
| 308 | // expected-error@-1 {{no member named 'await_ready'}} |
| 309 | } |
| 310 | template <class R, class U> |
| 311 | coro<R> dep_mem_fn(U u) { co_await u; } |
| 312 | }; |
| 313 | |
| 314 | awaitable operator co_await(await_arg_2); // expected-note {{'operator co_await' should be declared prior to the call site}} |
| 315 | |
| 316 | template struct dependent_member<basic_promise<await_arg_1>, 0>; |
| 317 | template struct dependent_member<basic_promise<await_arg_2>, 0>; // expected-note {{in instantiation}} |
| 318 | |
| 319 | template <> |
| 320 | coro<transform_promise> |
| 321 | // FIXME this diagnostic is terrible |
| 322 | dependent_member<long>::dep_mem_fn<transform_promise>(int) { // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::transformed'}} |
| 323 | //expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 324 | //expected-note@+1 {{function is a coroutine due to use of 'co_await' here}} |
| 325 | co_await transform_awaitable{}; |
| 326 | // expected-error@-1 {{no member named 'await_ready'}} |
| 327 | } |
| 328 | |
| 329 | void operator co_await(transform_awaitable) = delete; |
| 330 | awaitable operator co_await(transformed); |
| 331 | |
| 332 | template coro<transform_promise> |
| 333 | dependent_member<long>::dep_mem_fn<transform_promise>(transform_awaitable); |
| 334 | |
| 335 | template <> |
| 336 | coro<transform_promise> dependent_member<long>::dep_mem_fn<transform_promise>(long) { |
| 337 | co_await transform_awaitable{}; |
| 338 | } |
| 339 | |
| 340 | template <> |
| 341 | struct dependent_member<int> { |
| 342 | coro<transform_promise> mem_fn() const { |
| 343 | co_await transform_awaitable{}; |
| 344 | } |
| 345 | }; |
| 346 | |
| 347 | template coro<transform_promise> await_template_3<transform_promise>(transform_awaitable); |
| 348 | template struct dependent_member<transform_promise>; |
| 349 | template coro<transform_promise> dependent_member<transform_promise>::dep_mem_fn(transform_awaitable); |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 350 | } |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 351 | |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 352 | struct yield_fn_tag {}; |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 353 | template <> |
| 354 | struct std::experimental::coroutine_traits<void, yield_fn_tag> { |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 355 | struct promise_type { |
| 356 | // FIXME: add an await_transform overload for functions |
| 357 | awaitable yield_value(int()); |
| 358 | void return_value(int()); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 359 | |
| 360 | suspend_never initial_suspend(); |
| 361 | suspend_never final_suspend(); |
| 362 | void get_return_object(); |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 363 | }; |
| 364 | }; |
| 365 | |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 366 | namespace placeholder { |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 367 | awaitable f(), f(int); // expected-note 4{{possible target}} |
| 368 | int g(), g(int); // expected-note 2{{candidate}} |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 369 | void x() { |
| 370 | co_await f; // expected-error {{reference to overloaded function}} |
| 371 | } |
| 372 | void y() { |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 373 | co_yield g; // expected-error {{no matching member function for call to 'yield_value'}} |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 374 | } |
| 375 | void z() { |
| 376 | co_await a; |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 377 | co_return g; // expected-error {{address of overloaded function 'g' does not match required type 'int'}} |
| 378 | } |
| 379 | |
| 380 | void x(yield_fn_tag) { |
| 381 | co_await f; // expected-error {{reference to overloaded function}} |
| 382 | } |
| 383 | void y(yield_fn_tag) { |
| 384 | co_yield g; |
| 385 | } |
| 386 | void z(yield_fn_tag) { |
| 387 | co_await a; |
| 388 | co_return g; |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 389 | } |
| 390 | } |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 391 | |
| 392 | struct bad_promise_1 { |
| 393 | suspend_always initial_suspend(); |
| 394 | suspend_always final_suspend(); |
| 395 | }; |
| 396 | coro<bad_promise_1> missing_get_return_object() { // expected-error {{no member named 'get_return_object' in 'bad_promise_1'}} |
| 397 | co_await a; |
| 398 | } |
| 399 | |
| 400 | struct bad_promise_2 { |
| 401 | coro<bad_promise_2> get_return_object(); |
| 402 | // FIXME: We shouldn't offer a typo-correction here! |
| 403 | suspend_always final_suspend(); // expected-note {{here}} |
| 404 | }; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 405 | // FIXME: This shouldn't happen twice |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 406 | coro<bad_promise_2> missing_initial_suspend() { // expected-error {{no member named 'initial_suspend' in 'bad_promise_2'}} |
| 407 | co_await a; |
| 408 | } |
| 409 | |
| 410 | struct bad_promise_3 { |
| 411 | coro<bad_promise_3> get_return_object(); |
| 412 | // FIXME: We shouldn't offer a typo-correction here! |
| 413 | suspend_always initial_suspend(); // expected-note {{here}} |
| 414 | }; |
| 415 | coro<bad_promise_3> missing_final_suspend() { // expected-error {{no member named 'final_suspend' in 'bad_promise_3'}} |
| 416 | co_await a; |
| 417 | } |
| 418 | |
| 419 | struct bad_promise_4 { |
| 420 | coro<bad_promise_4> get_return_object(); |
| 421 | not_awaitable initial_suspend(); |
| 422 | suspend_always final_suspend(); |
| 423 | }; |
| 424 | // FIXME: This diagnostic is terrible. |
| 425 | coro<bad_promise_4> bad_initial_suspend() { // expected-error {{no member named 'await_ready' in 'not_awaitable'}} |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 426 | // expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 427 | co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}} |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | struct bad_promise_5 { |
| 431 | coro<bad_promise_5> get_return_object(); |
| 432 | suspend_always initial_suspend(); |
| 433 | not_awaitable final_suspend(); |
| 434 | }; |
| 435 | // FIXME: This diagnostic is terrible. |
| 436 | coro<bad_promise_5> bad_final_suspend() { // expected-error {{no member named 'await_ready' in 'not_awaitable'}} |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 437 | // expected-note@-1 {{call to 'final_suspend' implicitly required by the final suspend point}} |
| 438 | co_await a; // expected-note {{function is a coroutine due to use of 'co_await' here}} |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 439 | } |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 440 | |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 441 | struct bad_promise_6 { |
| 442 | coro<bad_promise_6> get_return_object(); |
| 443 | suspend_always initial_suspend(); |
| 444 | suspend_always final_suspend(); |
| 445 | void return_void(); |
| 446 | void return_value(int) const; |
| 447 | void return_value(int); |
| 448 | }; |
| 449 | coro<bad_promise_6> bad_implicit_return() { // expected-error {{'bad_promise_6' declares both 'return_value' and 'return_void'}} |
| 450 | co_await a; |
| 451 | } |
| 452 | |
| 453 | struct bad_promise_7 { |
| 454 | coro<bad_promise_7> get_return_object(); |
| 455 | suspend_always initial_suspend(); |
| 456 | suspend_always final_suspend(); |
| 457 | void return_void(); |
| 458 | void set_exception(int *); |
| 459 | }; |
| 460 | coro<bad_promise_7> no_std_current_exc() { |
| 461 | // expected-error@-1 {{you need to include <exception> before defining a coroutine that implicitly uses 'set_exception'}} |
| 462 | co_await a; |
| 463 | } |
| 464 | |
| 465 | namespace std { |
| 466 | int *current_exception(); |
| 467 | } |
| 468 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 469 | struct bad_promise_base { |
| 470 | private: |
| 471 | void return_void(); |
| 472 | }; |
| 473 | struct bad_promise_8 : bad_promise_base { |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 474 | coro<bad_promise_8> get_return_object(); |
| 475 | suspend_always initial_suspend(); |
| 476 | suspend_always final_suspend(); |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 477 | void set_exception(); // expected-note {{function not viable}} |
| 478 | void set_exception(int *) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}} |
| 479 | void set_exception(void *); // expected-note {{candidate function}} |
| 480 | }; |
| 481 | coro<bad_promise_8> calls_set_exception() { |
| 482 | // expected-error@-1 {{call to unavailable member function 'set_exception'}} |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 483 | // FIXME: also warn about private 'return_void' here. Even though building |
| 484 | // the call to set_exception has already failed. |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 485 | co_await a; |
| 486 | } |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 487 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 488 | struct bad_promise_9 { |
| 489 | coro<bad_promise_9> get_return_object(); |
| 490 | suspend_always initial_suspend(); |
| 491 | suspend_always final_suspend(); |
| 492 | void await_transform(void *); // expected-note {{candidate}} |
| 493 | awaitable await_transform(int) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}} |
| 494 | void return_void(); |
| 495 | }; |
| 496 | coro<bad_promise_9> calls_await_transform() { |
| 497 | co_await 42; // expected-error {{call to unavailable member function 'await_transform'}} |
| 498 | // expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}} |
| 499 | } |
| 500 | |
| 501 | struct bad_promise_10 { |
| 502 | coro<bad_promise_10> get_return_object(); |
| 503 | suspend_always initial_suspend(); |
| 504 | suspend_always final_suspend(); |
| 505 | int await_transform; |
| 506 | void return_void(); |
| 507 | }; |
| 508 | coro<bad_promise_10> bad_coawait() { |
| 509 | // FIXME this diagnostic is terrible |
| 510 | co_await 42; // expected-error {{called object type 'int' is not a function or function pointer}} |
| 511 | // expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}} |
| 512 | } |
| 513 | |
| 514 | struct call_operator { |
| 515 | template <class... Args> |
| 516 | awaitable operator()(Args...) const { return a; } |
| 517 | }; |
| 518 | void ret_void(); |
| 519 | struct good_promise_1 { |
| 520 | coro<good_promise_1> get_return_object(); |
| 521 | suspend_always initial_suspend(); |
| 522 | suspend_always final_suspend(); |
| 523 | static const call_operator await_transform; |
| 524 | using Fn = void (*)(); |
| 525 | Fn return_void = ret_void; |
| 526 | }; |
| 527 | const call_operator good_promise_1::await_transform; |
| 528 | coro<good_promise_1> ok_static_coawait() { |
| 529 | // FIXME this diagnostic is terrible |
| 530 | co_await 42; |
| 531 | } |
| 532 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 533 | template<> struct std::experimental::coroutine_traits<int, int, const char**> |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 534 | { using promise_type = promise; }; |
| 535 | |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 536 | int main(int, const char**) { |
| 537 | co_await a; // expected-error {{'co_await' cannot be used in the 'main' function}} |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 538 | } |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 539 | |
| 540 | struct good_promise_2 { |
| 541 | float get_return_object(); |
| 542 | suspend_always initial_suspend(); |
| 543 | suspend_always final_suspend(); |
| 544 | void return_void(); |
| 545 | }; |
| 546 | template<> struct std::experimental::coroutine_handle<good_promise_2> {}; |
| 547 | |
| 548 | template<> struct std::experimental::coroutine_traits<float> |
| 549 | { using promise_type = good_promise_2; }; |
| 550 | |
| 551 | float badly_specialized_coro_handle() { // expected-error {{std::experimental::coroutine_handle missing a member named 'from_address'}} |
| 552 | //expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 553 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 554 | } |