diff gcc/testsuite/g++.dg/coroutines/torture/co-ret-12-co-ret-fun-co-await.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/g++.dg/coroutines/torture/co-ret-12-co-ret-fun-co-await.C	Thu Feb 13 11:34:05 2020 +0900
@@ -0,0 +1,48 @@
+// { dg-do run }
+
+// Check co_return function (co_await)
+
+#include "../coro.h"
+
+// boiler-plate for tests of codegen
+#define USE_AWAIT_TRANSFORM
+#include "../coro1-ret-int-yield-int.h"
+
+__attribute__((__noinline__))
+static int
+foo (int x)
+{
+  return x + 2;
+}
+
+struct coro1
+f () noexcept
+{
+  PRINT ("coro1: about to return");
+  co_return foo (co_await 5);
+}
+
+int main ()
+{
+  PRINT ("main: create coro1");
+  struct coro1 x = f ();
+  PRINT ("main: got coro1 - resuming");
+  if (x.handle.done())
+    abort();
+
+  x.handle.resume();
+  PRINT ("main: after resume 1 (initial suspend)");
+  x.handle.resume();
+  PRINT ("main: after resume 2 (await parm)");
+
+  int y = x.handle.promise().get_value();
+  if ( y != 7 )
+    abort ();
+  if (!x.handle.done())
+    {
+      PRINT ("main: apparently not done...");
+      abort ();
+    }
+  PRINT ("main: returning");
+  return 0;
+}