| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s -fcxx-exceptions -fexceptions |
| 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 { |
| Eric Fiselier | 166c6e6 | 2017-07-10 01:27:22 +0000 | [diff] [blame] | 25 | |
| 26 | template <class... Args> |
| 27 | struct void_t_imp { |
| 28 | using type = void; |
| 29 | }; |
| 30 | template <class... Args> |
| 31 | using void_t = typename void_t_imp<Args...>::type; |
| 32 | |
| 33 | template <class T, class = void> |
| 34 | struct traits_sfinae_base {}; |
| 35 | |
| 36 | template <class T> |
| 37 | struct traits_sfinae_base<T, void_t<typename T::promise_type>> { |
| 38 | using promise_type = typename T::promise_type; |
| 39 | }; |
| 40 | |
| 41 | template <class Ret, class... Args> |
| 42 | struct coroutine_traits : public traits_sfinae_base<Ret> {}; |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 43 | }} // namespace std::experimental |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 44 | |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 45 | template<typename Promise> struct coro {}; |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 46 | template <typename Promise, typename... Ps> |
| 47 | struct std::experimental::coroutine_traits<coro<Promise>, Ps...> { |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 48 | using promise_type = Promise; |
| 49 | }; |
| 50 | |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 51 | struct awaitable { |
| 52 | bool await_ready(); |
| 53 | template <typename F> void await_suspend(F); |
| 54 | void await_resume(); |
| 55 | } a; |
| 56 | |
| 57 | struct suspend_always { |
| 58 | bool await_ready() { return false; } |
| 59 | template <typename F> void await_suspend(F); |
| 60 | void await_resume() {} |
| 61 | }; |
| 62 | |
| 63 | struct suspend_never { |
| 64 | bool await_ready() { return true; } |
| 65 | template <typename F> void await_suspend(F); |
| 66 | void await_resume() {} |
| 67 | }; |
| 68 | |
| Eric Fiselier | 166c6e6 | 2017-07-10 01:27:22 +0000 | [diff] [blame] | 69 | struct DummyVoidTag {}; |
| 70 | DummyVoidTag no_specialization() { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<DummyVoidTag>' has no member named 'promise_type'}} |
| 71 | co_await a; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 74 | template <typename... T> |
| 75 | struct std::experimental::coroutine_traits<int, T...> {}; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 76 | |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 77 | int no_promise_type() { // expected-error {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<int>' has no member named 'promise_type'}} |
| 78 | co_await a; |
| Richard Smith | 9b2f53e | 2015-11-19 02:36:35 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 81 | template <> |
| 82 | struct std::experimental::coroutine_traits<double, double> { typedef int promise_type; }; |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 83 | 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}} |
| 84 | co_await a; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 87 | template <> |
| 88 | struct std::experimental::coroutine_traits<double, int> { |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 89 | struct promise_type {}; |
| 90 | }; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 91 | 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] | 92 | 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] | 93 | } |
| 94 | |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 95 | struct promise; // expected-note {{forward declaration}} |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 96 | struct promise_void; |
| 97 | struct void_tag {}; |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 98 | template <typename... T> |
| 99 | struct std::experimental::coroutine_traits<void, T...> { using promise_type = promise; }; |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 100 | template <typename... T> |
| 101 | struct std::experimental::coroutine_traits<void, void_tag, T...> |
| 102 | { using promise_type = promise_void; }; |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 103 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 104 | // FIXME: This diagnostic is terrible. |
| Eric Fiselier | 89bf0e7 | 2017-03-06 22:52:28 +0000 | [diff] [blame] | 105 | 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] | 106 | co_await a; |
| 107 | } |
| 108 | |
| Richard Smith | ae3d147 | 2015-11-20 22:47:10 +0000 | [diff] [blame] | 109 | struct yielded_thing { const char *p; short a, b; }; |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 110 | |
| Richard Smith | d7bed4d | 2015-11-22 02:57:17 +0000 | [diff] [blame] | 111 | struct not_awaitable {}; |
| 112 | |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 113 | struct promise { |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 114 | void get_return_object(); |
| 115 | suspend_always initial_suspend(); |
| 116 | suspend_always final_suspend(); |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 117 | awaitable yield_value(int); // expected-note 2{{candidate}} |
| 118 | awaitable yield_value(yielded_thing); // expected-note 2{{candidate}} |
| 119 | not_awaitable yield_value(void()); // expected-note 2{{candidate}} |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 120 | void return_value(int); // expected-note 2{{here}} |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 121 | void unhandled_exception(); |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 124 | struct promise_void { |
| 125 | void get_return_object(); |
| 126 | suspend_always initial_suspend(); |
| 127 | suspend_always final_suspend(); |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 128 | void return_void(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 129 | void unhandled_exception(); |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 132 | void no_coroutine_handle() { // expected-error {{std::experimental::coroutine_handle type was not found; include <experimental/coroutine> before defining a coroutine}} |
| 133 | //expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 134 | co_return 5; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 135 | } |
| 136 | |
| 137 | namespace std { |
| 138 | namespace experimental { |
| 139 | template <class PromiseType = void> |
| 140 | struct coroutine_handle { |
| 141 | static coroutine_handle from_address(void *); |
| 142 | }; |
| 143 | template <> |
| 144 | struct coroutine_handle<void> { |
| 145 | template <class PromiseType> |
| 146 | coroutine_handle(coroutine_handle<PromiseType>); |
| 147 | static coroutine_handle from_address(void *); |
| 148 | }; |
| 149 | }} // namespace std::experimental |
| 150 | |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 151 | void yield() { |
| 152 | co_yield 0; |
| Richard Smith | ae3d147 | 2015-11-20 22:47:10 +0000 | [diff] [blame] | 153 | co_yield {"foo", 1, 2}; |
| 154 | co_yield {1e100}; // expected-error {{cannot be narrowed}} expected-note {{explicit cast}} expected-warning {{changes value}} expected-warning {{braces around scalar}} |
| 155 | co_yield {"foo", __LONG_LONG_MAX__}; // expected-error {{cannot be narrowed}} expected-note {{explicit cast}} expected-warning {{changes value}} |
| 156 | co_yield {"foo"}; |
| Richard Smith | 23da82c | 2015-11-20 22:40:06 +0000 | [diff] [blame] | 157 | co_yield "foo"; // expected-error {{no matching}} |
| Richard Smith | d7bed4d | 2015-11-22 02:57:17 +0000 | [diff] [blame] | 158 | co_yield 1.0; |
| 159 | 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] | 160 | } |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 161 | |
| Richard Smith | 4ba6660 | 2015-11-22 07:05:16 +0000 | [diff] [blame] | 162 | void coreturn(int n) { |
| 163 | co_await a; |
| 164 | if (n == 0) |
| 165 | co_return 3; |
| 166 | if (n == 1) |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 167 | co_return {4}; // expected-warning {{braces around scalar initializer}} |
| Richard Smith | 4ba6660 | 2015-11-22 07:05:16 +0000 | [diff] [blame] | 168 | if (n == 2) |
| 169 | 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] | 170 | co_return 42; |
| Richard Smith | 4ba6660 | 2015-11-22 07:05:16 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| Eric Fiselier | 8d409e8 | 2017-03-09 05:01:31 +0000 | [diff] [blame] | 173 | template <class T> |
| 174 | void co_await_non_dependent_arg(T) { |
| 175 | co_await a; |
| 176 | } |
| 177 | template void co_await_non_dependent_arg(int); |
| 178 | |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 179 | void mixed_yield() { |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 180 | co_yield 0; // expected-note {{use of 'co_yield'}} |
| 181 | return; // expected-error {{not allowed in coroutine}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| Eric Fiselier | cac0a59 | 2017-03-11 02:35:37 +0000 | [diff] [blame] | 184 | void mixed_yield_invalid() { |
| 185 | co_yield blah; // expected-error {{use of undeclared identifier}} |
| 186 | // expected-note@-1 {{function is a coroutine due to use of 'co_yield'}} |
| 187 | return; // expected-error {{return statement not allowed in coroutine}} |
| 188 | } |
| 189 | |
| 190 | template <class T> |
| 191 | void mixed_yield_template(T) { |
| 192 | co_yield blah; // expected-error {{use of undeclared identifier}} |
| 193 | // expected-note@-1 {{function is a coroutine due to use of 'co_yield'}} |
| 194 | return; // expected-error {{return statement not allowed in coroutine}} |
| 195 | } |
| 196 | |
| 197 | template <class T> |
| 198 | void mixed_yield_template2(T) { |
| 199 | co_yield 42; |
| 200 | // expected-note@-1 {{function is a coroutine due to use of 'co_yield'}} |
| 201 | return; // expected-error {{return statement not allowed in coroutine}} |
| 202 | } |
| 203 | |
| 204 | template <class T> |
| 205 | void mixed_yield_template3(T v) { |
| 206 | co_yield blah(v); |
| 207 | // expected-note@-1 {{function is a coroutine due to use of 'co_yield'}} |
| 208 | return; // expected-error {{return statement not allowed in coroutine}} |
| 209 | } |
| 210 | |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 211 | void mixed_await() { |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 212 | co_await a; // expected-note {{use of 'co_await'}} |
| 213 | return; // expected-error {{not allowed in coroutine}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| Eric Fiselier | cac0a59 | 2017-03-11 02:35:37 +0000 | [diff] [blame] | 216 | void mixed_await_invalid() { |
| 217 | co_await 42; // expected-error {{'int' is not a structure or union}} |
| 218 | // expected-note@-1 {{function is a coroutine due to use of 'co_await'}} |
| 219 | return; // expected-error {{not allowed in coroutine}} |
| 220 | } |
| 221 | |
| 222 | template <class T> |
| 223 | void mixed_await_template(T) { |
| 224 | co_await 42; |
| 225 | // expected-note@-1 {{function is a coroutine due to use of 'co_await'}} |
| 226 | return; // expected-error {{not allowed in coroutine}} |
| 227 | } |
| 228 | |
| 229 | template <class T> |
| 230 | void mixed_await_template2(T v) { |
| 231 | co_await v; // expected-error {{'long' is not a structure or union}} |
| 232 | // expected-note@-1 {{function is a coroutine due to use of 'co_await'}} |
| 233 | return; // expected-error {{not allowed in coroutine}} |
| 234 | } |
| 235 | template void mixed_await_template2(long); // expected-note {{requested here}} |
| 236 | |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 237 | void only_coreturn(void_tag) { |
| Gor Nishanov | d97f6bf | 2017-01-10 00:08:31 +0000 | [diff] [blame] | 238 | co_return; // OK |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| Eric Fiselier | 9813131 | 2016-10-06 21:23:38 +0000 | [diff] [blame] | 241 | void mixed_coreturn(void_tag, bool b) { |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 242 | if (b) |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 243 | co_return; // expected-note {{use of 'co_return'}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 244 | else |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 245 | return; // expected-error {{not allowed in coroutine}} |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| Eric Fiselier | cac0a59 | 2017-03-11 02:35:37 +0000 | [diff] [blame] | 248 | void mixed_coreturn_invalid(bool b) { |
| 249 | if (b) |
| 250 | co_return; // expected-note {{use of 'co_return'}} |
| 251 | // expected-error@-1 {{no member named 'return_void' in 'promise'}} |
| 252 | else |
| 253 | return; // expected-error {{not allowed in coroutine}} |
| 254 | } |
| 255 | |
| 256 | template <class T> |
| 257 | void mixed_coreturn_template(void_tag, bool b, T v) { |
| 258 | if (b) |
| 259 | co_return v; // expected-note {{use of 'co_return'}} |
| 260 | // expected-error@-1 {{no member named 'return_value' in 'promise_void'}} |
| 261 | else |
| 262 | return; // expected-error {{not allowed in coroutine}} |
| 263 | } |
| 264 | template void mixed_coreturn_template(void_tag, bool, int); // expected-note {{requested here}} |
| 265 | |
| 266 | template <class T> |
| 267 | void mixed_coreturn_template2(bool b, T) { |
| 268 | if (b) |
| 269 | co_return v; // expected-note {{use of 'co_return'}} |
| 270 | // expected-error@-1 {{use of undeclared identifier 'v'}} |
| 271 | else |
| 272 | return; // expected-error {{not allowed in coroutine}} |
| 273 | } |
| 274 | |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 275 | struct CtorDtor { |
| 276 | CtorDtor() { |
| 277 | co_yield 0; // expected-error {{'co_yield' cannot be used in a constructor}} |
| 278 | } |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 279 | CtorDtor(awaitable a) { |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 280 | // 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] | 281 | 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] | 282 | } |
| 283 | ~CtorDtor() { |
| 284 | co_return 0; // expected-error {{'co_return' cannot be used in a destructor}} |
| 285 | } |
| 286 | // FIXME: The spec says this is ill-formed. |
| 287 | void operator=(CtorDtor&) { |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 288 | co_yield 0; // expected-error {{'co_yield' cannot be used in a copy assignment operator}} |
| 289 | } |
| 290 | void operator=(CtorDtor const &) { |
| 291 | co_yield 0; // expected-error {{'co_yield' cannot be used in a copy assignment operator}} |
| 292 | } |
| 293 | void operator=(CtorDtor &&) { |
| 294 | co_await a; // expected-error {{'co_await' cannot be used in a move assignment operator}} |
| 295 | } |
| 296 | void operator=(CtorDtor const &&) { |
| 297 | co_await a; // expected-error {{'co_await' cannot be used in a move assignment operator}} |
| 298 | } |
| 299 | void operator=(int) { |
| 300 | co_await a; // OK. Not a special member |
| Richard Smith | cfd53b4 | 2015-10-22 06:13:50 +0000 | [diff] [blame] | 301 | } |
| 302 | }; |
| 303 | |
| Richard Smith | 744b224 | 2015-11-20 02:54:01 +0000 | [diff] [blame] | 304 | void unevaluated() { |
| 305 | decltype(co_await a); // expected-error {{cannot be used in an unevaluated context}} |
| 306 | sizeof(co_await a); // expected-error {{cannot be used in an unevaluated context}} |
| 307 | typeid(co_await a); // expected-error {{cannot be used in an unevaluated context}} |
| 308 | decltype(co_yield a); // expected-error {{cannot be used in an unevaluated context}} |
| 309 | sizeof(co_yield a); // expected-error {{cannot be used in an unevaluated context}} |
| 310 | typeid(co_yield a); // expected-error {{cannot be used in an unevaluated context}} |
| 311 | } |
| 312 | |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 313 | constexpr auto constexpr_deduced_return_coroutine() { |
| Richard Smith | 744b224 | 2015-11-20 02:54:01 +0000 | [diff] [blame] | 314 | 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] | 315 | // 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] | 316 | } |
| 317 | |
| 318 | void varargs_coroutine(const char *, ...) { |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 319 | co_await a; // expected-error {{'co_await' cannot be used in a varargs function}} |
| 320 | } |
| 321 | |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 322 | auto deduced_return_coroutine() { |
| 323 | co_await a; // expected-error {{'co_await' cannot be used in a function with a deduced return type}} |
| 324 | } |
| 325 | |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 326 | struct outer {}; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 327 | struct await_arg_1 {}; |
| 328 | struct await_arg_2 {}; |
| 329 | |
| 330 | namespace adl_ns { |
| 331 | struct coawait_arg_type {}; |
| 332 | awaitable operator co_await(coawait_arg_type); |
| 333 | } |
| Richard Smith | 9f690bd | 2015-10-27 06:02:45 +0000 | [diff] [blame] | 334 | |
| 335 | namespace dependent_operator_co_await_lookup { |
| 336 | template<typename T> void await_template(T t) { |
| 337 | // no unqualified lookup results |
| 338 | co_await t; // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::not_awaitable'}} |
| 339 | // expected-error@-1 {{call to function 'operator co_await' that is neither visible in the template definition nor found by argument-dependent lookup}} |
| 340 | }; |
| 341 | template void await_template(awaitable); |
| 342 | |
| 343 | struct indirectly_awaitable { indirectly_awaitable(outer); }; |
| 344 | awaitable operator co_await(indirectly_awaitable); // expected-note {{should be declared prior to}} |
| 345 | template void await_template(indirectly_awaitable); |
| 346 | |
| 347 | struct not_awaitable {}; |
| 348 | template void await_template(not_awaitable); // expected-note {{instantiation}} |
| 349 | |
| 350 | template<typename T> void await_template_2(T t) { |
| 351 | // one unqualified lookup result |
| 352 | co_await t; |
| 353 | }; |
| 354 | template void await_template(outer); // expected-note {{instantiation}} |
| 355 | template void await_template_2(outer); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 356 | |
| 357 | struct transform_awaitable {}; |
| 358 | struct transformed {}; |
| 359 | |
| 360 | struct transform_promise { |
| 361 | typedef transform_awaitable await_arg; |
| 362 | coro<transform_promise> get_return_object(); |
| 363 | transformed initial_suspend(); |
| 364 | ::adl_ns::coawait_arg_type final_suspend(); |
| 365 | transformed await_transform(transform_awaitable); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 366 | void unhandled_exception(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 367 | void return_void(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 368 | }; |
| 369 | template <class AwaitArg> |
| 370 | struct basic_promise { |
| 371 | typedef AwaitArg await_arg; |
| 372 | coro<basic_promise> get_return_object(); |
| 373 | awaitable initial_suspend(); |
| 374 | awaitable final_suspend(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 375 | void unhandled_exception(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 376 | void return_void(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | awaitable operator co_await(await_arg_1); |
| 380 | |
| 381 | template <typename T, typename U> |
| 382 | coro<T> await_template_3(U t) { |
| 383 | co_await t; |
| 384 | } |
| 385 | |
| 386 | template coro<basic_promise<await_arg_1>> await_template_3<basic_promise<await_arg_1>>(await_arg_1); |
| 387 | |
| 388 | template <class T, int I = 0> |
| 389 | struct dependent_member { |
| 390 | coro<T> mem_fn() const { |
| 391 | co_await typename T::await_arg{}; // expected-error {{call to function 'operator co_await'}}} |
| 392 | } |
| 393 | template <class U> |
| 394 | coro<T> dep_mem_fn(U t) { |
| 395 | co_await t; |
| 396 | } |
| 397 | }; |
| 398 | |
| 399 | template <> |
| 400 | struct dependent_member<long> { |
| 401 | // FIXME this diagnostic is terrible |
| 402 | coro<transform_promise> mem_fn() const { // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::transformed'}} |
| 403 | // expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 404 | // expected-note@+1 {{function is a coroutine due to use of 'co_await' here}} |
| 405 | co_await transform_awaitable{}; |
| 406 | // expected-error@-1 {{no member named 'await_ready'}} |
| 407 | } |
| 408 | template <class R, class U> |
| 409 | coro<R> dep_mem_fn(U u) { co_await u; } |
| 410 | }; |
| 411 | |
| 412 | awaitable operator co_await(await_arg_2); // expected-note {{'operator co_await' should be declared prior to the call site}} |
| 413 | |
| 414 | template struct dependent_member<basic_promise<await_arg_1>, 0>; |
| 415 | template struct dependent_member<basic_promise<await_arg_2>, 0>; // expected-note {{in instantiation}} |
| 416 | |
| 417 | template <> |
| 418 | coro<transform_promise> |
| 419 | // FIXME this diagnostic is terrible |
| 420 | dependent_member<long>::dep_mem_fn<transform_promise>(int) { // expected-error {{no member named 'await_ready' in 'dependent_operator_co_await_lookup::transformed'}} |
| 421 | //expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 422 | //expected-note@+1 {{function is a coroutine due to use of 'co_await' here}} |
| 423 | co_await transform_awaitable{}; |
| 424 | // expected-error@-1 {{no member named 'await_ready'}} |
| 425 | } |
| 426 | |
| 427 | void operator co_await(transform_awaitable) = delete; |
| 428 | awaitable operator co_await(transformed); |
| 429 | |
| 430 | template coro<transform_promise> |
| 431 | dependent_member<long>::dep_mem_fn<transform_promise>(transform_awaitable); |
| 432 | |
| 433 | template <> |
| 434 | coro<transform_promise> dependent_member<long>::dep_mem_fn<transform_promise>(long) { |
| 435 | co_await transform_awaitable{}; |
| 436 | } |
| 437 | |
| 438 | template <> |
| 439 | struct dependent_member<int> { |
| 440 | coro<transform_promise> mem_fn() const { |
| 441 | co_await transform_awaitable{}; |
| 442 | } |
| 443 | }; |
| 444 | |
| 445 | template coro<transform_promise> await_template_3<transform_promise>(transform_awaitable); |
| 446 | template struct dependent_member<transform_promise>; |
| 447 | 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] | 448 | } |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 449 | |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 450 | struct yield_fn_tag {}; |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 451 | template <> |
| 452 | struct std::experimental::coroutine_traits<void, yield_fn_tag> { |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 453 | struct promise_type { |
| 454 | // FIXME: add an await_transform overload for functions |
| 455 | awaitable yield_value(int()); |
| 456 | void return_value(int()); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 457 | |
| 458 | suspend_never initial_suspend(); |
| 459 | suspend_never final_suspend(); |
| 460 | void get_return_object(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 461 | void unhandled_exception(); |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 462 | }; |
| 463 | }; |
| 464 | |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 465 | namespace placeholder { |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 466 | awaitable f(), f(int); // expected-note 4{{possible target}} |
| 467 | int g(), g(int); // expected-note 2{{candidate}} |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 468 | void x() { |
| 469 | co_await f; // expected-error {{reference to overloaded function}} |
| 470 | } |
| 471 | void y() { |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 472 | 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] | 473 | } |
| 474 | void z() { |
| 475 | co_await a; |
| Richard Smith | 71d403e | 2015-11-22 07:33:28 +0000 | [diff] [blame] | 476 | co_return g; // expected-error {{address of overloaded function 'g' does not match required type 'int'}} |
| 477 | } |
| 478 | |
| 479 | void x(yield_fn_tag) { |
| 480 | co_await f; // expected-error {{reference to overloaded function}} |
| 481 | } |
| 482 | void y(yield_fn_tag) { |
| 483 | co_yield g; |
| 484 | } |
| 485 | void z(yield_fn_tag) { |
| 486 | co_await a; |
| 487 | co_return g; |
| Richard Smith | 10610f7 | 2015-11-20 22:57:24 +0000 | [diff] [blame] | 488 | } |
| 489 | } |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 490 | |
| 491 | struct bad_promise_1 { |
| 492 | suspend_always initial_suspend(); |
| 493 | suspend_always final_suspend(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 494 | void unhandled_exception(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 495 | void return_void(); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 496 | }; |
| 497 | coro<bad_promise_1> missing_get_return_object() { // expected-error {{no member named 'get_return_object' in 'bad_promise_1'}} |
| 498 | co_await a; |
| 499 | } |
| 500 | |
| 501 | struct bad_promise_2 { |
| 502 | coro<bad_promise_2> get_return_object(); |
| 503 | // FIXME: We shouldn't offer a typo-correction here! |
| 504 | suspend_always final_suspend(); // expected-note {{here}} |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 505 | void unhandled_exception(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 506 | void return_void(); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 507 | }; |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 508 | // FIXME: This shouldn't happen twice |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 509 | coro<bad_promise_2> missing_initial_suspend() { // expected-error {{no member named 'initial_suspend' in 'bad_promise_2'}} |
| 510 | co_await a; |
| 511 | } |
| 512 | |
| 513 | struct bad_promise_3 { |
| 514 | coro<bad_promise_3> get_return_object(); |
| 515 | // FIXME: We shouldn't offer a typo-correction here! |
| 516 | suspend_always initial_suspend(); // expected-note {{here}} |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 517 | void unhandled_exception(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 518 | void return_void(); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 519 | }; |
| 520 | coro<bad_promise_3> missing_final_suspend() { // expected-error {{no member named 'final_suspend' in 'bad_promise_3'}} |
| 521 | co_await a; |
| 522 | } |
| 523 | |
| 524 | struct bad_promise_4 { |
| 525 | coro<bad_promise_4> get_return_object(); |
| 526 | not_awaitable initial_suspend(); |
| 527 | suspend_always final_suspend(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 528 | void return_void(); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 529 | }; |
| 530 | // FIXME: This diagnostic is terrible. |
| 531 | 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] | 532 | // expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 533 | 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] | 534 | } |
| 535 | |
| 536 | struct bad_promise_5 { |
| 537 | coro<bad_promise_5> get_return_object(); |
| 538 | suspend_always initial_suspend(); |
| 539 | not_awaitable final_suspend(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 540 | void return_void(); |
| Richard Smith | 2af65c4 | 2015-11-24 02:34:39 +0000 | [diff] [blame] | 541 | }; |
| 542 | // FIXME: This diagnostic is terrible. |
| 543 | 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] | 544 | // expected-note@-1 {{call to 'final_suspend' implicitly required by the final suspend point}} |
| 545 | 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] | 546 | } |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 547 | |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 548 | struct bad_promise_6 { |
| 549 | coro<bad_promise_6> get_return_object(); |
| 550 | suspend_always initial_suspend(); |
| 551 | suspend_always final_suspend(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 552 | void unhandled_exception(); |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 553 | void return_void(); // expected-note 2 {{member 'return_void' first declared here}} |
| 554 | void return_value(int) const; // expected-note 2 {{member 'return_value' first declared here}} |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 555 | void return_value(int); |
| 556 | }; |
| 557 | coro<bad_promise_6> bad_implicit_return() { // expected-error {{'bad_promise_6' declares both 'return_value' and 'return_void'}} |
| 558 | co_await a; |
| 559 | } |
| 560 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 561 | template <class T> |
| 562 | coro<T> bad_implicit_return_dependent(T) { // expected-error {{'bad_promise_6' declares both 'return_value' and 'return_void'}} |
| 563 | co_await a; |
| 564 | } |
| 565 | template coro<bad_promise_6> bad_implicit_return_dependent(bad_promise_6); // expected-note {{in instantiation}} |
| 566 | |
| Gor Nishanov | 29ff638 | 2017-05-24 14:34:19 +0000 | [diff] [blame] | 567 | struct bad_promise_7 { // expected-note 2 {{defined here}} |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 568 | coro<bad_promise_7> get_return_object(); |
| 569 | suspend_always initial_suspend(); |
| 570 | suspend_always final_suspend(); |
| 571 | void return_void(); |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 572 | }; |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 573 | coro<bad_promise_7> no_unhandled_exception() { // expected-error {{'bad_promise_7' is required to declare the member 'unhandled_exception()'}} |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 574 | co_await a; |
| 575 | } |
| 576 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 577 | template <class T> |
| 578 | coro<T> no_unhandled_exception_dependent(T) { // expected-error {{'bad_promise_7' is required to declare the member 'unhandled_exception()'}} |
| 579 | co_await a; |
| 580 | } |
| 581 | template coro<bad_promise_7> no_unhandled_exception_dependent(bad_promise_7); // expected-note {{in instantiation}} |
| 582 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 583 | struct bad_promise_base { |
| 584 | private: |
| 585 | void return_void(); |
| 586 | }; |
| 587 | struct bad_promise_8 : bad_promise_base { |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 588 | coro<bad_promise_8> get_return_object(); |
| 589 | suspend_always initial_suspend(); |
| 590 | suspend_always final_suspend(); |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 591 | void unhandled_exception() __attribute__((unavailable)); // expected-note 2 {{made unavailable}} |
| 592 | void unhandled_exception() const; // expected-note 2 {{candidate}} |
| 593 | void unhandled_exception(void *) const; // expected-note 2 {{requires 1 argument, but 0 were provided}} |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 594 | }; |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 595 | coro<bad_promise_8> calls_unhandled_exception() { |
| 596 | // expected-error@-1 {{call to unavailable member function 'unhandled_exception'}} |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 597 | // FIXME: also warn about private 'return_void' here. Even though building |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 598 | // the call to unhandled_exception has already failed. |
| Eric Fiselier | 709d1b3 | 2016-10-27 07:30:31 +0000 | [diff] [blame] | 599 | co_await a; |
| 600 | } |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 601 | |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 602 | template <class T> |
| 603 | coro<T> calls_unhandled_exception_dependent(T) { |
| 604 | // expected-error@-1 {{call to unavailable member function 'unhandled_exception'}} |
| 605 | co_await a; |
| 606 | } |
| 607 | template coro<bad_promise_8> calls_unhandled_exception_dependent(bad_promise_8); // expected-note {{in instantiation}} |
| 608 | |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 609 | struct bad_promise_9 { |
| 610 | coro<bad_promise_9> get_return_object(); |
| 611 | suspend_always initial_suspend(); |
| 612 | suspend_always final_suspend(); |
| 613 | void await_transform(void *); // expected-note {{candidate}} |
| 614 | awaitable await_transform(int) __attribute__((unavailable)); // expected-note {{explicitly made unavailable}} |
| 615 | void return_void(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 616 | void unhandled_exception(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 617 | }; |
| 618 | coro<bad_promise_9> calls_await_transform() { |
| 619 | co_await 42; // expected-error {{call to unavailable member function 'await_transform'}} |
| 620 | // expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}} |
| 621 | } |
| 622 | |
| 623 | struct bad_promise_10 { |
| 624 | coro<bad_promise_10> get_return_object(); |
| 625 | suspend_always initial_suspend(); |
| 626 | suspend_always final_suspend(); |
| 627 | int await_transform; |
| 628 | void return_void(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 629 | void unhandled_exception(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 630 | }; |
| 631 | coro<bad_promise_10> bad_coawait() { |
| 632 | // FIXME this diagnostic is terrible |
| 633 | co_await 42; // expected-error {{called object type 'int' is not a function or function pointer}} |
| 634 | // expected-note@-1 {{call to 'await_transform' implicitly required by 'co_await' here}} |
| 635 | } |
| 636 | |
| 637 | struct call_operator { |
| 638 | template <class... Args> |
| 639 | awaitable operator()(Args...) const { return a; } |
| 640 | }; |
| 641 | void ret_void(); |
| 642 | struct good_promise_1 { |
| 643 | coro<good_promise_1> get_return_object(); |
| 644 | suspend_always initial_suspend(); |
| 645 | suspend_always final_suspend(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 646 | void unhandled_exception(); |
| Eric Fiselier | 20f25cb | 2017-03-06 23:38:15 +0000 | [diff] [blame] | 647 | static const call_operator await_transform; |
| 648 | using Fn = void (*)(); |
| 649 | Fn return_void = ret_void; |
| 650 | }; |
| 651 | const call_operator good_promise_1::await_transform; |
| 652 | coro<good_promise_1> ok_static_coawait() { |
| 653 | // FIXME this diagnostic is terrible |
| 654 | co_await 42; |
| 655 | } |
| 656 | |
| Gor Nishanov | 3e048bb | 2016-10-04 00:31:16 +0000 | [diff] [blame] | 657 | template<> struct std::experimental::coroutine_traits<int, int, const char**> |
| Eric Fiselier | 7d5773e | 2016-09-30 22:38:31 +0000 | [diff] [blame] | 658 | { using promise_type = promise; }; |
| 659 | |
| Eric Fiselier | c8efda7 | 2016-10-27 18:43:28 +0000 | [diff] [blame] | 660 | int main(int, const char**) { |
| 661 | 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] | 662 | } |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 663 | |
| 664 | struct good_promise_2 { |
| 665 | float get_return_object(); |
| 666 | suspend_always initial_suspend(); |
| 667 | suspend_always final_suspend(); |
| 668 | void return_void(); |
| Eric Fiselier | a9fdb34 | 2017-03-23 00:33:33 +0000 | [diff] [blame] | 669 | void unhandled_exception(); |
| Gor Nishanov | 6dcb0eb | 2017-03-09 03:09:43 +0000 | [diff] [blame] | 670 | }; |
| 671 | template<> struct std::experimental::coroutine_handle<good_promise_2> {}; |
| 672 | |
| 673 | template<> struct std::experimental::coroutine_traits<float> |
| 674 | { using promise_type = good_promise_2; }; |
| 675 | |
| 676 | float badly_specialized_coro_handle() { // expected-error {{std::experimental::coroutine_handle missing a member named 'from_address'}} |
| 677 | //expected-note@-1 {{call to 'initial_suspend' implicitly required by the initial suspend point}} |
| 678 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 679 | } |
| Gor Nishanov | 3aa9eb3 | 2017-03-27 23:36:59 +0000 | [diff] [blame] | 680 | |
| Eric Fiselier | f692e7d | 2017-04-18 03:12:48 +0000 | [diff] [blame] | 681 | namespace std { |
| 682 | struct nothrow_t {}; |
| 683 | constexpr nothrow_t nothrow = {}; |
| 684 | } |
| 685 | |
| 686 | using SizeT = decltype(sizeof(int)); |
| 687 | |
| 688 | void* operator new(SizeT __sz, const std::nothrow_t&) noexcept; |
| 689 | void operator delete(void* __p, const std::nothrow_t&) noexcept; |
| 690 | |
| 691 | |
| 692 | |
| Gor Nishanov | 3aa9eb3 | 2017-03-27 23:36:59 +0000 | [diff] [blame] | 693 | struct promise_on_alloc_failure_tag {}; |
| 694 | |
| 695 | template<> |
| 696 | struct std::experimental::coroutine_traits<int, promise_on_alloc_failure_tag> { |
| 697 | struct promise_type { |
| 698 | int get_return_object() {} |
| 699 | suspend_always initial_suspend() { return {}; } |
| 700 | suspend_always final_suspend() { return {}; } |
| 701 | void return_void() {} |
| 702 | int get_return_object_on_allocation_failure(); // expected-error{{'promise_type': 'get_return_object_on_allocation_failure()' must be a static member function}} |
| 703 | void unhandled_exception(); |
| 704 | }; |
| 705 | }; |
| 706 | |
| 707 | extern "C" int f(promise_on_alloc_failure_tag) { |
| 708 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 709 | } |
| Eric Fiselier | bee782b | 2017-04-03 19:21:00 +0000 | [diff] [blame] | 710 | |
| 711 | struct bad_promise_11 { |
| 712 | coro<bad_promise_11> get_return_object(); |
| 713 | suspend_always initial_suspend(); |
| 714 | suspend_always final_suspend(); |
| 715 | void unhandled_exception(); |
| 716 | void return_void(); |
| 717 | |
| 718 | private: |
| 719 | static coro<bad_promise_11> get_return_object_on_allocation_failure(); // expected-note 2 {{declared private here}} |
| 720 | }; |
| 721 | coro<bad_promise_11> private_alloc_failure_handler() { |
| 722 | // expected-error@-1 {{'get_return_object_on_allocation_failure' is a private member of 'bad_promise_11'}} |
| 723 | co_return; // FIXME: Add a "declared coroutine here" note. |
| 724 | } |
| 725 | |
| 726 | template <class T> |
| 727 | coro<T> dependent_private_alloc_failure_handler(T) { |
| 728 | // expected-error@-1 {{'get_return_object_on_allocation_failure' is a private member of 'bad_promise_11'}} |
| 729 | co_return; // FIXME: Add a "declared coroutine here" note. |
| 730 | } |
| 731 | template coro<bad_promise_11> dependent_private_alloc_failure_handler(bad_promise_11); |
| 732 | // expected-note@-1 {{requested here}} |
| Eric Fiselier | f692e7d | 2017-04-18 03:12:48 +0000 | [diff] [blame] | 733 | |
| 734 | struct bad_promise_12 { |
| 735 | coro<bad_promise_12> get_return_object(); |
| 736 | suspend_always initial_suspend(); |
| 737 | suspend_always final_suspend(); |
| 738 | void unhandled_exception(); |
| 739 | void return_void(); |
| 740 | static coro<bad_promise_12> get_return_object_on_allocation_failure(); |
| 741 | |
| 742 | static void* operator new(SizeT); |
| 743 | // 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()'}} |
| 744 | }; |
| 745 | coro<bad_promise_12> throwing_in_class_new() { // expected-note {{call to 'operator new' implicitly required by coroutine function here}} |
| 746 | co_return; |
| 747 | } |
| 748 | |
| 749 | template <class T> |
| 750 | coro<T> dependent_throwing_in_class_new(T) { // expected-note {{call to 'operator new' implicitly required by coroutine function here}} |
| 751 | co_return; |
| 752 | } |
| 753 | template coro<bad_promise_12> dependent_throwing_in_class_new(bad_promise_12); // expected-note {{requested here}} |
| 754 | |
| 755 | |
| 756 | struct good_promise_13 { |
| 757 | coro<good_promise_13> get_return_object(); |
| 758 | suspend_always initial_suspend(); |
| 759 | suspend_always final_suspend(); |
| 760 | void unhandled_exception(); |
| 761 | void return_void(); |
| 762 | static coro<good_promise_13> get_return_object_on_allocation_failure(); |
| 763 | }; |
| 764 | coro<good_promise_13> uses_nothrow_new() { |
| 765 | co_return; |
| 766 | } |
| 767 | |
| 768 | template <class T> |
| 769 | coro<T> dependent_uses_nothrow_new(T) { |
| 770 | co_return; |
| 771 | } |
| 772 | template coro<good_promise_13> dependent_uses_nothrow_new(good_promise_13); |
| Gor Nishanov | 6a47068 | 2017-05-22 20:22:23 +0000 | [diff] [blame] | 773 | |
| 774 | struct mismatch_gro_type_tag1 {}; |
| 775 | template<> |
| 776 | struct std::experimental::coroutine_traits<int, mismatch_gro_type_tag1> { |
| 777 | struct promise_type { |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 778 | void get_return_object() {} //expected-note {{member 'get_return_object' declared here}} |
| Gor Nishanov | 6a47068 | 2017-05-22 20:22:23 +0000 | [diff] [blame] | 779 | suspend_always initial_suspend() { return {}; } |
| 780 | suspend_always final_suspend() { return {}; } |
| 781 | void return_void() {} |
| 782 | void unhandled_exception(); |
| 783 | }; |
| 784 | }; |
| 785 | |
| 786 | extern "C" int f(mismatch_gro_type_tag1) { |
| 787 | // expected-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'void'}} |
| 788 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 789 | } |
| 790 | |
| 791 | struct mismatch_gro_type_tag2 {}; |
| 792 | template<> |
| 793 | struct std::experimental::coroutine_traits<int, mismatch_gro_type_tag2> { |
| 794 | struct promise_type { |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 795 | void *get_return_object() {} //expected-note {{member 'get_return_object' declared here}} |
| Gor Nishanov | 6a47068 | 2017-05-22 20:22:23 +0000 | [diff] [blame] | 796 | suspend_always initial_suspend() { return {}; } |
| 797 | suspend_always final_suspend() { return {}; } |
| 798 | void return_void() {} |
| 799 | void unhandled_exception(); |
| 800 | }; |
| 801 | }; |
| 802 | |
| 803 | extern "C" int f(mismatch_gro_type_tag2) { |
| 804 | // expected-error@-1 {{cannot initialize return object of type 'int' with an lvalue of type 'void *'}} |
| 805 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 806 | } |
| 807 | |
| 808 | struct mismatch_gro_type_tag3 {}; |
| 809 | template<> |
| 810 | struct std::experimental::coroutine_traits<int, mismatch_gro_type_tag3> { |
| 811 | struct promise_type { |
| 812 | int get_return_object() {} |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 813 | static void get_return_object_on_allocation_failure() {} //expected-note {{member 'get_return_object_on_allocation_failure' declared here}} |
| Gor Nishanov | 6a47068 | 2017-05-22 20:22:23 +0000 | [diff] [blame] | 814 | suspend_always initial_suspend() { return {}; } |
| 815 | suspend_always final_suspend() { return {}; } |
| 816 | void return_void() {} |
| 817 | void unhandled_exception(); |
| 818 | }; |
| 819 | }; |
| 820 | |
| 821 | extern "C" int f(mismatch_gro_type_tag3) { |
| 822 | // expected-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'void'}} |
| 823 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 824 | } |
| 825 | |
| 826 | |
| 827 | struct mismatch_gro_type_tag4 {}; |
| 828 | template<> |
| 829 | struct std::experimental::coroutine_traits<int, mismatch_gro_type_tag4> { |
| 830 | struct promise_type { |
| 831 | int get_return_object() {} |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 832 | static char *get_return_object_on_allocation_failure() {} //expected-note {{member 'get_return_object_on_allocation_failure' declared}} |
| Gor Nishanov | 6a47068 | 2017-05-22 20:22:23 +0000 | [diff] [blame] | 833 | suspend_always initial_suspend() { return {}; } |
| 834 | suspend_always final_suspend() { return {}; } |
| 835 | void return_void() {} |
| 836 | void unhandled_exception(); |
| 837 | }; |
| 838 | }; |
| 839 | |
| 840 | extern "C" int f(mismatch_gro_type_tag4) { |
| 841 | // expected-error@-1 {{cannot initialize return object of type 'int' with an rvalue of type 'char *'}} |
| 842 | co_return; //expected-note {{function is a coroutine due to use of 'co_return' here}} |
| 843 | } |
| 844 | |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 845 | struct bad_promise_no_return_func { // expected-note {{'bad_promise_no_return_func' defined here}} |
| Eric Fiselier | da8f9b5 | 2017-05-25 02:16:53 +0000 | [diff] [blame] | 846 | coro<bad_promise_no_return_func> get_return_object(); |
| 847 | suspend_always initial_suspend(); |
| 848 | suspend_always final_suspend(); |
| 849 | void unhandled_exception(); |
| 850 | }; |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 851 | // FIXME: The PDTS currently specifies this as UB, technically forbidding a |
| 852 | // diagnostic. |
| Eric Fiselier | da8f9b5 | 2017-05-25 02:16:53 +0000 | [diff] [blame] | 853 | coro<bad_promise_no_return_func> no_return_value_or_return_void() { |
| Eric Fiselier | fc50f62 | 2017-05-25 14:59:39 +0000 | [diff] [blame] | 854 | // expected-error@-1 {{'bad_promise_no_return_func' must declare either 'return_value' or 'return_void'}} |
| Eric Fiselier | da8f9b5 | 2017-05-25 02:16:53 +0000 | [diff] [blame] | 855 | co_await a; |
| 856 | } |
| Eric Fiselier | d978e53 | 2017-05-28 18:21:12 +0000 | [diff] [blame] | 857 | |
| 858 | struct bad_await_suspend_return { |
| 859 | bool await_ready(); |
| Eric Fiselier | 84ee7ff | 2017-05-31 23:41:11 +0000 | [diff] [blame] | 860 | // expected-error@+1 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'char')}} |
| Eric Fiselier | d978e53 | 2017-05-28 18:21:12 +0000 | [diff] [blame] | 861 | char await_suspend(std::experimental::coroutine_handle<>); |
| 862 | void await_resume(); |
| 863 | }; |
| 864 | struct bad_await_ready_return { |
| Eric Fiselier | 84ee7ff | 2017-05-31 23:41:11 +0000 | [diff] [blame] | 865 | // expected-note@+1 {{return type of 'await_ready' is required to be contextually convertible to 'bool'}} |
| Eric Fiselier | d978e53 | 2017-05-28 18:21:12 +0000 | [diff] [blame] | 866 | void await_ready(); |
| 867 | bool await_suspend(std::experimental::coroutine_handle<>); |
| 868 | void await_resume(); |
| 869 | }; |
| 870 | struct await_ready_explicit_bool { |
| 871 | struct BoolT { |
| 872 | explicit operator bool() const; |
| 873 | }; |
| 874 | BoolT await_ready(); |
| 875 | void await_suspend(std::experimental::coroutine_handle<>); |
| 876 | void await_resume(); |
| 877 | }; |
| Eric Fiselier | 84ee7ff | 2017-05-31 23:41:11 +0000 | [diff] [blame] | 878 | template <class SuspendTy> |
| 879 | struct await_suspend_type_test { |
| 880 | bool await_ready(); |
| 881 | // expected-error@+2 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'bool &')}} |
| 882 | // expected-error@+1 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'bool &&')}} |
| 883 | SuspendTy await_suspend(std::experimental::coroutine_handle<>); |
| 884 | void await_resume(); |
| 885 | }; |
| Eric Fiselier | d978e53 | 2017-05-28 18:21:12 +0000 | [diff] [blame] | 886 | void test_bad_suspend() { |
| 887 | { |
| 888 | // FIXME: The actual error emitted here is terrible, and no number of notes can save it. |
| 889 | bad_await_ready_return a; |
| 890 | // expected-error@+1 {{value of type 'void' is not contextually convertible to 'bool'}} |
| 891 | co_await a; // expected-note {{call to 'await_ready' implicitly required by coroutine function here}} |
| 892 | } |
| 893 | { |
| 894 | bad_await_suspend_return b; |
| 895 | co_await b; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}} |
| 896 | } |
| 897 | { |
| 898 | await_ready_explicit_bool c; |
| 899 | co_await c; // OK |
| 900 | } |
| Eric Fiselier | 84ee7ff | 2017-05-31 23:41:11 +0000 | [diff] [blame] | 901 | { |
| 902 | await_suspend_type_test<bool &&> a; |
| 903 | await_suspend_type_test<bool &> b; |
| 904 | await_suspend_type_test<const void> c; |
| 905 | await_suspend_type_test<const volatile bool> d; |
| 906 | co_await a; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}} |
| 907 | co_await b; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}} |
| 908 | co_await c; // OK |
| 909 | co_await d; // OK |
| 910 | } |
| Eric Fiselier | d978e53 | 2017-05-28 18:21:12 +0000 | [diff] [blame] | 911 | } |
| Eric Fiselier | de7943b | 2017-06-03 00:22:18 +0000 | [diff] [blame] | 912 | |
| 913 | template <int ID = 0> |
| 914 | struct NoCopy { |
| 915 | NoCopy(NoCopy const&) = delete; // expected-note 2 {{deleted here}} |
| 916 | }; |
| 917 | template <class T, class U> |
| 918 | void test_dependent_param(T t, U) { |
| 919 | // expected-error@-1 {{call to deleted constructor of 'NoCopy<0>'}} |
| 920 | // expected-error@-2 {{call to deleted constructor of 'NoCopy<1>'}} |
| 921 | ((void)t); |
| 922 | co_return 42; |
| 923 | } |
| 924 | template void test_dependent_param(NoCopy<0>, NoCopy<1>); // expected-note {{requested here}} |
| Eric Fiselier | 166c6e6 | 2017-07-10 01:27:22 +0000 | [diff] [blame] | 925 | |
| 926 | namespace CoroHandleMemberFunctionTest { |
| 927 | struct CoroMemberTag {}; |
| 928 | struct BadCoroMemberTag {}; |
| 929 | |
| 930 | template <class T, class U> |
| 931 | constexpr bool IsSameV = false; |
| 932 | template <class T> |
| 933 | constexpr bool IsSameV<T, T> = true; |
| 934 | |
| 935 | template <class T> |
| 936 | struct TypeTest { |
| 937 | template <class U> |
| 938 | static constexpr bool IsSame = IsSameV<T, U>; |
| 939 | |
| 940 | template <class... Args> |
| 941 | static constexpr bool MatchesArgs = IsSameV<T, |
| 942 | std::experimental::coroutine_traits<CoroMemberTag, Args...>>; |
| 943 | }; |
| 944 | |
| 945 | template <class T> |
| 946 | struct AwaitReturnsType { |
| 947 | bool await_ready() const; |
| 948 | void await_suspend(...) const; |
| 949 | T await_resume() const; |
| 950 | }; |
| 951 | |
| 952 | template <class... CoroTraitsArgs> |
| 953 | struct CoroMemberPromise { |
| 954 | using TraitsT = std::experimental::coroutine_traits<CoroTraitsArgs...>; |
| 955 | using TypeTestT = TypeTest<TraitsT>; |
| 956 | using AwaitTestT = AwaitReturnsType<TypeTestT>; |
| 957 | |
| 958 | CoroMemberTag get_return_object(); |
| 959 | suspend_always initial_suspend(); |
| 960 | suspend_always final_suspend(); |
| 961 | |
| 962 | AwaitTestT yield_value(int); |
| 963 | |
| 964 | void return_void(); |
| 965 | void unhandled_exception(); |
| 966 | }; |
| 967 | |
| 968 | } // namespace CoroHandleMemberFunctionTest |
| 969 | |
| 970 | template <class... Args> |
| 971 | struct ::std::experimental::coroutine_traits<CoroHandleMemberFunctionTest::CoroMemberTag, Args...> { |
| 972 | using promise_type = CoroHandleMemberFunctionTest::CoroMemberPromise<CoroHandleMemberFunctionTest::CoroMemberTag, Args...>; |
| 973 | }; |
| 974 | |
| 975 | namespace CoroHandleMemberFunctionTest { |
| 976 | struct TestType { |
| 977 | |
| 978 | CoroMemberTag test_qual() { |
| 979 | auto TC = co_yield 0; |
| 980 | static_assert(TC.MatchesArgs<TestType &>, ""); |
| 981 | static_assert(!TC.MatchesArgs<TestType>, ""); |
| 982 | static_assert(!TC.MatchesArgs<TestType *>, ""); |
| 983 | } |
| 984 | |
| 985 | CoroMemberTag test_sanity(int *) const { |
| 986 | auto TC = co_yield 0; |
| 987 | static_assert(TC.MatchesArgs<const TestType &>, ""); // expected-error {{static_assert failed}} |
| 988 | static_assert(TC.MatchesArgs<const TestType &>, ""); // expected-error {{static_assert failed}} |
| 989 | static_assert(TC.MatchesArgs<const TestType &, int *>, ""); |
| 990 | } |
| 991 | |
| 992 | CoroMemberTag test_qual(int *, const float &&, volatile void *volatile) const { |
| 993 | auto TC = co_yield 0; |
| 994 | static_assert(TC.MatchesArgs<const TestType &, int *, const float &&, volatile void *volatile>, ""); |
| 995 | } |
| 996 | |
| 997 | CoroMemberTag test_qual() const volatile { |
| 998 | auto TC = co_yield 0; |
| 999 | static_assert(TC.MatchesArgs<const volatile TestType &>, ""); |
| 1000 | } |
| 1001 | |
| 1002 | CoroMemberTag test_ref_qual() & { |
| 1003 | auto TC = co_yield 0; |
| 1004 | static_assert(TC.MatchesArgs<TestType &>, ""); |
| 1005 | } |
| 1006 | CoroMemberTag test_ref_qual() const & { |
| 1007 | auto TC = co_yield 0; |
| 1008 | static_assert(TC.MatchesArgs<TestType const &>, ""); |
| 1009 | } |
| 1010 | CoroMemberTag test_ref_qual() && { |
| 1011 | auto TC = co_yield 0; |
| 1012 | static_assert(TC.MatchesArgs<TestType &&>, ""); |
| 1013 | } |
| 1014 | CoroMemberTag test_ref_qual(const char *&) const volatile && { |
| 1015 | auto TC = co_yield 0; |
| 1016 | static_assert(TC.MatchesArgs<TestType const volatile &&, const char *&>, ""); |
| 1017 | } |
| 1018 | |
| 1019 | CoroMemberTag test_args(int) { |
| 1020 | auto TC = co_yield 0; |
| 1021 | static_assert(TC.MatchesArgs<TestType &, int>, ""); |
| 1022 | } |
| 1023 | CoroMemberTag test_args(int, long &, void *) const { |
| 1024 | auto TC = co_yield 0; |
| 1025 | static_assert(TC.MatchesArgs<TestType const &, int, long &, void *>, ""); |
| 1026 | } |
| 1027 | |
| 1028 | template <class... Args> |
| 1029 | CoroMemberTag test_member_template(Args...) const && { |
| 1030 | auto TC = co_yield 0; |
| 1031 | static_assert(TC.template MatchesArgs<TestType const &&, Args...>, ""); |
| 1032 | } |
| 1033 | |
| 1034 | static CoroMemberTag test_static() { |
| 1035 | auto TC = co_yield 0; |
| 1036 | static_assert(TC.MatchesArgs<>, ""); |
| 1037 | static_assert(!TC.MatchesArgs<TestType>, ""); |
| 1038 | static_assert(!TC.MatchesArgs<TestType &>, ""); |
| 1039 | static_assert(!TC.MatchesArgs<TestType *>, ""); |
| 1040 | } |
| 1041 | |
| 1042 | static CoroMemberTag test_static(volatile void *const, char &&) { |
| 1043 | auto TC = co_yield 0; |
| 1044 | static_assert(TC.MatchesArgs<volatile void *const, char &&>, ""); |
| 1045 | } |
| 1046 | |
| 1047 | template <class Dummy> |
| 1048 | static CoroMemberTag test_static_template(const char *volatile &, unsigned) { |
| 1049 | auto TC = co_yield 0; |
| 1050 | using TCT = decltype(TC); |
| 1051 | static_assert(TCT::MatchesArgs<const char *volatile &, unsigned>, ""); |
| 1052 | static_assert(!TCT::MatchesArgs<TestType &, const char *volatile &, unsigned>, ""); |
| 1053 | } |
| 1054 | |
| 1055 | BadCoroMemberTag test_diagnostics() { |
| 1056 | // expected-error@-1 {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<CoroHandleMemberFunctionTest::BadCoroMemberTag, CoroHandleMemberFunctionTest::TestType &>' has no member named 'promise_type'}} |
| 1057 | co_return; |
| 1058 | } |
| 1059 | BadCoroMemberTag test_diagnostics(int) const && { |
| 1060 | // expected-error@-1 {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<CoroHandleMemberFunctionTest::BadCoroMemberTag, const CoroHandleMemberFunctionTest::TestType &&, int>' has no member named 'promise_type'}} |
| 1061 | co_return; |
| 1062 | } |
| 1063 | |
| 1064 | static BadCoroMemberTag test_static_diagnostics(long *) { |
| 1065 | // expected-error@-1 {{this function cannot be a coroutine: 'std::experimental::coroutine_traits<CoroHandleMemberFunctionTest::BadCoroMemberTag, long *>' has no member named 'promise_type'}} |
| 1066 | co_return; |
| 1067 | } |
| 1068 | }; |
| 1069 | |
| 1070 | template CoroMemberTag TestType::test_member_template(long, const char *) const &&; |
| 1071 | template CoroMemberTag TestType::test_static_template<void>(const char *volatile &, unsigned); |
| 1072 | |
| 1073 | template <class... Args> |
| 1074 | struct DepTestType { |
| 1075 | |
| 1076 | CoroMemberTag test_sanity(int *) const { |
| 1077 | auto TC = co_yield 0; |
| 1078 | static_assert(TC.template MatchesArgs<const DepTestType &>, ""); // expected-error {{static_assert failed}} |
| 1079 | static_assert(TC.template MatchesArgs<>, ""); // expected-error {{static_assert failed}} |
| 1080 | static_assert(TC.template MatchesArgs<const DepTestType &, int *>, ""); |
| 1081 | } |
| 1082 | |
| 1083 | CoroMemberTag test_qual() { |
| 1084 | auto TC = co_yield 0; |
| 1085 | static_assert(TC.template MatchesArgs<DepTestType &>, ""); |
| 1086 | static_assert(!TC.template MatchesArgs<DepTestType>, ""); |
| 1087 | static_assert(!TC.template MatchesArgs<DepTestType *>, ""); |
| 1088 | } |
| 1089 | |
| 1090 | CoroMemberTag test_qual(int *, const float &&, volatile void *volatile) const { |
| 1091 | auto TC = co_yield 0; |
| 1092 | static_assert(TC.template MatchesArgs<const DepTestType &, int *, const float &&, volatile void *volatile>, ""); |
| 1093 | } |
| 1094 | |
| 1095 | CoroMemberTag test_qual() const volatile { |
| 1096 | auto TC = co_yield 0; |
| 1097 | static_assert(TC.template MatchesArgs<const volatile DepTestType &>, ""); |
| 1098 | } |
| 1099 | |
| 1100 | CoroMemberTag test_ref_qual() & { |
| 1101 | auto TC = co_yield 0; |
| 1102 | static_assert(TC.template MatchesArgs<DepTestType &>, ""); |
| 1103 | } |
| 1104 | CoroMemberTag test_ref_qual() const & { |
| 1105 | auto TC = co_yield 0; |
| 1106 | static_assert(TC.template MatchesArgs<DepTestType const &>, ""); |
| 1107 | } |
| 1108 | CoroMemberTag test_ref_qual() && { |
| 1109 | auto TC = co_yield 0; |
| 1110 | static_assert(TC.template MatchesArgs<DepTestType &&>, ""); |
| 1111 | } |
| 1112 | CoroMemberTag test_ref_qual(const char *&) const volatile && { |
| 1113 | auto TC = co_yield 0; |
| 1114 | static_assert(TC.template MatchesArgs<DepTestType const volatile &&, const char *&>, ""); |
| 1115 | } |
| 1116 | |
| 1117 | CoroMemberTag test_args(int) { |
| 1118 | auto TC = co_yield 0; |
| 1119 | static_assert(TC.template MatchesArgs<DepTestType &, int>, ""); |
| 1120 | } |
| 1121 | CoroMemberTag test_args(int, long &, void *) const { |
| 1122 | auto TC = co_yield 0; |
| 1123 | static_assert(TC.template MatchesArgs<DepTestType const &, int, long &, void *>, ""); |
| 1124 | } |
| 1125 | |
| 1126 | template <class... UArgs> |
| 1127 | CoroMemberTag test_member_template(UArgs...) const && { |
| 1128 | auto TC = co_yield 0; |
| 1129 | static_assert(TC.template MatchesArgs<DepTestType const &&, UArgs...>, ""); |
| 1130 | } |
| 1131 | |
| 1132 | static CoroMemberTag test_static() { |
| 1133 | auto TC = co_yield 0; |
| 1134 | using TCT = decltype(TC); |
| 1135 | static_assert(TCT::MatchesArgs<>, ""); |
| 1136 | static_assert(!TCT::MatchesArgs<DepTestType>, ""); |
| 1137 | static_assert(!TCT::MatchesArgs<DepTestType &>, ""); |
| 1138 | static_assert(!TCT::MatchesArgs<DepTestType *>, ""); |
| 1139 | |
| 1140 | // Ensure diagnostics are actually being generated here |
| 1141 | static_assert(TCT::MatchesArgs<int>, ""); // expected-error {{static_assert failed}} |
| 1142 | } |
| 1143 | |
| 1144 | static CoroMemberTag test_static(volatile void *const, char &&) { |
| 1145 | auto TC = co_yield 0; |
| 1146 | using TCT = decltype(TC); |
| 1147 | static_assert(TCT::MatchesArgs<volatile void *const, char &&>, ""); |
| 1148 | } |
| 1149 | |
| 1150 | template <class Dummy> |
| 1151 | static CoroMemberTag test_static_template(const char *volatile &, unsigned) { |
| 1152 | auto TC = co_yield 0; |
| 1153 | using TCT = decltype(TC); |
| 1154 | static_assert(TCT::MatchesArgs<const char *volatile &, unsigned>, ""); |
| 1155 | static_assert(!TCT::MatchesArgs<DepTestType &, const char *volatile &, unsigned>, ""); |
| 1156 | } |
| 1157 | }; |
| 1158 | |
| 1159 | template struct DepTestType<int>; // expected-note {{requested here}} |
| 1160 | template CoroMemberTag DepTestType<int>::test_member_template(long, const char *) const &&; |
| 1161 | |
| 1162 | template CoroMemberTag DepTestType<int>::test_static_template<void>(const char *volatile &, unsigned); |
| 1163 | |
| 1164 | } // namespace CoroHandleMemberFunctionTest |