aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2020-02-23 15:44:20 +0000
committerIain Sandoe <iain@sandoe.co.uk>2020-03-01 17:18:45 +0000
commit26e78220c71829523181592eb5047538a6e35a99 (patch)
tree15ea917a6c6d1398b7c415c1511cfec7ea942c44
parent957a1b14e99596610abb0777ca86a1c80dde24e0 (diff)
downloadgcc-26e78220c71829523181592eb5047538a6e35a99.zip
gcc-26e78220c71829523181592eb5047538a6e35a99.tar.gz
gcc-26e78220c71829523181592eb5047538a6e35a99.tar.bz2
coroutines: Test that we correctly use class data members.
Improve test coverage, NFC. gcc/testsuite/ChangeLog: 2020-03-01 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/torture/class-07-data-member.C: New test.
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/coroutines/torture/class-07-data-member.C61
2 files changed, 65 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fd3eeba..35b1a3c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2020-03-01 Iain Sandoe <iain@sandoe.co.uk>
+
+ * g++.dg/coroutines/torture/class-07-data-member.C: New test.
+
2020-03-01 Paul Thomas <pault@gcc.gnu.org>
PR fortran/92976
diff --git a/gcc/testsuite/g++.dg/coroutines/torture/class-07-data-member.C b/gcc/testsuite/g++.dg/coroutines/torture/class-07-data-member.C
new file mode 100644
index 0000000..00a0df6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/torture/class-07-data-member.C
@@ -0,0 +1,61 @@
+// { dg-do run }
+
+// Show that we are correctly accessing class variables.
+
+#include "../coro.h"
+
+// boiler-plate for tests of codegen
+#include "../coro1-ret-int-yield-int.h"
+
+class Foo
+{
+ int v;
+ public:
+ Foo () : v(0) {};
+ Foo (int x) : v(x) {};
+ coro1 meth ()
+ {
+ PRINT ("coro1: about to return");
+ co_return v++;
+ }
+};
+
+int main ()
+{
+ Foo inst (42);
+ int y;
+ {
+ PRINT ("main: create coro1 [instance 1]");
+ coro1 x = inst.meth ();
+ if (x.handle.done())
+ abort();
+ PRINT ("main: got coro1 - resuming (initial suspend)");
+ x.handle.resume();
+ PRINT ("main: after resume");
+ y = x.handle.promise().get_value();
+ if ( y != 42 )
+ abort ();
+ if (!x.handle.done())
+ {
+ PRINT ("main: apparently not done...");
+ abort ();
+ }
+ }
+ PRINT ("main: create coro1 [instance 2]");
+ coro1 p = inst.meth ();
+ if (p.handle.done())
+ abort();
+ PRINT ("main: got coro1 - resuming (initial suspend)");
+ p.handle.resume();
+ PRINT ("main: after resume");
+ y = p.handle.promise().get_value();
+ if ( y != 43 )
+ abort ();
+ if (!p.handle.done())
+ {
+ PRINT ("main: apparently not done...");
+ abort ();
+ }
+ PRINT ("main: returning");
+ return 0;
+}