Mercurial > hg > CbC > CbC_gcc
view gcc/testsuite/g++.dg/coroutines/torture/co-yield-08-more-refs.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
line wrap: on
line source
// { dg-do run } // Check co_return co_await #include "../coro.h" // boiler-plate for tests of codegen #include "../coro1-ret-int-yield-int.h" /* Tests for . */ struct test { auto operator co_await() & noexcept { return coro1::suspend_always_intprt{}; } auto operator co_await() && noexcept { return coro1::suspend_always_longprtsq(3L); } }; struct coro1 f (test thing) noexcept { co_yield co_await static_cast<test&&>(thing); co_return 6174; } int main () { PRINT ("main: create coro1"); struct coro1 x = f (test{}); if (x.handle.done()) abort(); PRINT ("main: resuming (initial suspend)"); x.handle.resume(); PRINT ("main: resuming (await intprt)"); x.handle.resume(); int y = x.handle.promise().get_value(); if ( y != 9 ) { PRINTF ("main: co-yield gave %d, should be 9\n", y); abort (); } PRINT ("main: got coro1 - resuming (co_yield)"); if (x.handle.done()) abort(); x.handle.resume(); y = x.handle.promise().get_value(); if ( y != 6174 ) { PRINTF ("main: co-return gave %d, should be 9\n", y); abort (); } if (!x.handle.done()) { PRINT ("main: apparently not done..."); abort (); } PRINT ("main: returning"); return 0; }