coroutines: Update tests for get-return-object errors.
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 24 Jun 2020 15:10:12 +0000 (16:10 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 24 Jun 2020 20:04:51 +0000 (21:04 +0100)
We updated the handling of the errors for cases when the
ramp return cannot be constructed from the user's provided
get-return-object method.  This updates the testcases to
cover this.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/void-gro-non-class-coro.C: Moved to...
* g++.dg/coroutines/coro-bad-gro-01-void-gro-non-class-coro.C: ...here.
* g++.dg/coroutines/coro-bad-gro-00-class-gro-scalar-return.C: New test.

gcc/testsuite/g++.dg/coroutines/coro-bad-gro-00-class-gro-scalar-return.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/coro-bad-gro-01-void-gro-non-class-coro.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/void-gro-non-class-coro.C [deleted file]

diff --git a/gcc/testsuite/g++.dg/coroutines/coro-bad-gro-00-class-gro-scalar-return.C b/gcc/testsuite/g++.dg/coroutines/coro-bad-gro-00-class-gro-scalar-return.C
new file mode 100644 (file)
index 0000000..bd9dec6
--- /dev/null
@@ -0,0 +1,65 @@
+// Test handling of the case where we have a class g-r-o and a non-void
+// and non-class-type ramp return.
+
+#include "coro.h"
+
+int g_promise = -1;
+
+struct Thing {
+  double x;
+  Thing () : x(0.0) {}
+  ~Thing () {}
+};
+
+template<typename R, typename HandleRef, typename ...T>
+struct std::coroutine_traits<R, HandleRef, T...> {
+    struct promise_type {
+        promise_type (HandleRef h, T ...args)
+        { h = std::coroutine_handle<promise_type>::from_promise (*this);
+          PRINT ("Created Promise");
+          g_promise = 1;
+        }
+       ~promise_type () { PRINT ("Destroyed Promise"); g_promise = 0;}
+        Thing get_return_object() { return {}; }
+
+        auto initial_suspend() {
+          return std::suspend_always{};
+         }
+        auto final_suspend() { return std::suspend_never{}; }
+
+        void return_void() {}
+        void unhandled_exception() {}
+    };
+};
+
+int
+my_coro (std::coroutine_handle<>& h)
+{
+  PRINT ("coro1: about to return");
+  co_return;
+} // { dg-error {'struct Thing' used where a 'int' was expected} }
+
+int main ()
+{
+  std::coroutine_handle<> h;
+  int t = my_coro (h);
+
+  if (h.done())
+    {
+      PRINT ("main: apparently was already done...");
+      abort ();
+    }
+
+  // initial suspend.
+  h.resume ();
+
+  // The coro should have self-destructed.
+  if (g_promise)
+    {
+      PRINT ("main: apparently we did not complete...");
+      abort ();
+    }
+
+  PRINT ("main: returning");
+  return t;
+}
diff --git a/gcc/testsuite/g++.dg/coroutines/coro-bad-gro-01-void-gro-non-class-coro.C b/gcc/testsuite/g++.dg/coroutines/coro-bad-gro-01-void-gro-non-class-coro.C
new file mode 100644 (file)
index 0000000..c31fcb5
--- /dev/null
@@ -0,0 +1,59 @@
+// Test handling of the case where we have a void g-r-o and a non-void
+// and non-class-type ramp return.
+
+#include "coro.h"
+
+int g_promise = -1;
+
+template<typename R, typename HandleRef, typename ...T>
+struct std::coroutine_traits<R, HandleRef, T...> {
+    struct promise_type {
+        promise_type (HandleRef h, T ...args)
+        { h = std::coroutine_handle<promise_type>::from_promise (*this);
+          PRINT ("Created Promise");
+          g_promise = 1;
+        }
+       ~promise_type () { PRINT ("Destroyed Promise"); g_promise = 0;}
+        void get_return_object() {}
+
+        auto initial_suspend() {
+          return std::suspend_always{};
+         }
+        auto final_suspend() { return std::suspend_never{}; }
+
+        void return_void() {}
+        void unhandled_exception() {}
+    };
+};
+
+int
+my_coro (std::coroutine_handle<>& h)
+{
+  PRINT ("coro1: about to return");
+  co_return;
+} // { dg-error {cannot initialize a return object of type 'int' with an rvalue of type 'void'} }
+
+int main ()
+{
+  std::coroutine_handle<> h;
+  int t = my_coro (h);
+
+  if (h.done())
+    {
+      PRINT ("main: apparently was already done...");
+      abort ();
+    }
+
+  // initial suspend.
+  h.resume ();
+
+  // The coro should have self-destructed.
+  if (g_promise)
+    {
+      PRINT ("main: apparently we did not complete...");
+      abort ();
+    }
+
+  PRINT ("main: returning");
+  return t;
+}
diff --git a/gcc/testsuite/g++.dg/coroutines/void-gro-non-class-coro.C b/gcc/testsuite/g++.dg/coroutines/void-gro-non-class-coro.C
deleted file mode 100644 (file)
index 8176c8a..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// Test handling of the case where we have a void g-r-o and a non-void
-// and non-class-type ramp return.
-
-#include "coro.h"
-
-int g_promise = -1;
-
-template<typename R, typename HandleRef, typename ...T>
-struct std::coroutine_traits<R, HandleRef, T...> {
-    struct promise_type {
-        promise_type (HandleRef h, T ...args)
-        { h = std::coroutine_handle<promise_type>::from_promise (*this);
-          PRINT ("Created Promise");
-          g_promise = 1;
-        }
-       ~promise_type () { PRINT ("Destroyed Promise"); g_promise = 0;}
-        void get_return_object() {}
-
-        auto initial_suspend() {
-          return std::suspend_always{};
-         }
-        auto final_suspend() { return std::suspend_never{}; }
-
-        void return_void() {}
-        void unhandled_exception() {}
-    };
-};
-
-int
-my_coro (std::coroutine_handle<>& h)
-{
-  PRINT ("coro1: about to return");
-  co_return;
-} // { dg-error {cannot initialize a return object of type 'int' with an rvalue of type 'void'} }
-
-int main ()
-{
-  std::coroutine_handle<> h;
-  int t = my_coro (h);
-
-  if (h.done())
-    {
-      PRINT ("main: apparently was already done...");
-      abort ();
-    }
-
-  // initial suspend.
-  h.resume ();
-
-  // The coro should have self-destructed.
-  if (g_promise)
-    {
-      PRINT ("main: apparently we did not complete...");
-      abort ();
-    }
-
-  PRINT ("main: returning");
-  return 0;
-}