diff gcc/testsuite/g++.dg/coroutines/torture/lambda-06-multi-capture.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/lambda-06-multi-capture.C	Thu Feb 13 11:34:05 2020 +0900
@@ -0,0 +1,48 @@
+//  { dg-do run }
+
+// lambda with parm and local state
+
+#include "../coro.h"
+
+// boiler-plate for tests of codegen
+#include "../coro1-ret-int-yield-int.h"
+
+int main ()
+{
+  int a_copy = 20;
+  int a_ref = 10;
+
+  auto f = [&, a_copy]() -> coro1
+  {
+    co_return a_ref + a_copy;
+  };
+
+  {
+    coro1 A = f ();
+    A.handle.resume();
+    PRINT ("main: [a_copy = 20, a_ref = 10]");
+  
+    int y = A.handle.promise().get_value();
+    if (y != 30)
+      {
+	PRINTF ("main: A co-ret = %d, should be 30\n", y);
+	abort ();
+      }
+  }
+
+  a_copy = 5;
+  a_ref = 7;
+
+  coro1 B = f ();
+  B.handle.resume();
+  PRINT ("main: [a_copy = 5, a_ref = 7]");
+
+  int y = B.handle.promise().get_value();
+  if (y != 27)
+    {
+      PRINTF ("main: B co-ret = %d, should be 27\n", y);
+      abort ();
+    }
+  
+  return 0;
+}