public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8309] c++, coroutines: Account for overloaded promise return_value() [PR105301].
@ 2022-04-28 12:52 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2022-04-28 12:52 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6cae3bb65c873a2191613f7888fe949553a21f9e

commit r12-8309-g6cae3bb65c873a2191613f7888fe949553a21f9e
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Mon Apr 18 09:21:52 2022 +0100

    c++, coroutines: Account for overloaded promise return_value() [PR105301].
    
    Whether it was intended or not, it is possible to define a coroutine promise
    with multiple return_value() methods [which need not even have the same type].
    
    We were not accounting for this possibility in the check to see whether both
    return_value and return_void are specifier (which is prohibited by the
    standard).  Fixed thus and provided an adjusted diagnostic for the case that
    multiple return_value() methods are present.
    
    Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
    
            PR c++/105301
    
    gcc/cp/ChangeLog:
    
            * coroutines.cc (coro_promise_type_found_p): Account for possible
            mutliple overloads of the promise return_value() method.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/coroutines/pr105301.C: New test.

Diff:
---
 gcc/cp/coroutines.cc                       | 10 ++++--
 gcc/testsuite/g++.dg/coroutines/pr105301.C | 49 ++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 9b651b845b7..7f2377624eb 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -513,8 +513,14 @@ coro_promise_type_found_p (tree fndecl, location_t loc)
 		      coro_info->promise_type);
 	  inform (DECL_SOURCE_LOCATION (BASELINK_FUNCTIONS (has_ret_void)),
 		  "%<return_void%> declared here");
-	  inform (DECL_SOURCE_LOCATION (BASELINK_FUNCTIONS (has_ret_val)),
-		  "%<return_value%> declared here");
+	  has_ret_val = BASELINK_FUNCTIONS (has_ret_val);
+	  const char *message = "%<return_value%> declared here";
+	  if (TREE_CODE (has_ret_val) == OVERLOAD)
+	    {
+	      has_ret_val = OVL_FIRST (has_ret_val);
+	      message = "%<return_value%> first declared here";
+	    }
+	  inform (DECL_SOURCE_LOCATION (has_ret_val), message);
 	  coro_info->coro_co_return_error_emitted = true;
 	  return false;
 	}
diff --git a/gcc/testsuite/g++.dg/coroutines/pr105301.C b/gcc/testsuite/g++.dg/coroutines/pr105301.C
new file mode 100644
index 00000000000..33a0b03cf5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/pr105301.C
@@ -0,0 +1,49 @@
+// { dg-additional-options "-fsyntax-only" }
+namespace std {
+template <class T, class = void>
+struct traits_sfinae_base {};
+
+template <class Ret, class... Args>
+struct coroutine_traits : public traits_sfinae_base<Ret> {};
+}
+
+template<typename Promise> struct coro {};
+template <typename Promise, typename... Ps>
+struct std::coroutine_traits<coro<Promise>, Ps...> {
+  using promise_type = Promise;
+};
+
+struct awaitable {
+  bool await_ready() noexcept;
+  template <typename F>
+  void await_suspend(F) noexcept;
+  void await_resume() noexcept;
+} a;
+
+struct suspend_always {
+  bool await_ready() noexcept { return false; }
+  template <typename F>
+  void await_suspend(F) noexcept;
+  void await_resume() noexcept {}
+};
+
+namespace std {
+template <class PromiseType = void>
+struct coroutine_handle {};
+}
+
+struct bad_promise_6 {
+  coro<bad_promise_6> get_return_object();
+  suspend_always initial_suspend();
+  suspend_always final_suspend() noexcept;
+  void unhandled_exception();
+  void return_void();
+  void return_value(int) const;
+  void return_value(int);
+};
+
+coro<bad_promise_6>
+bad_implicit_return() // { dg-error {.aka 'bad_promise_6'. declares both 'return_value' and 'return_void'} }
+{
+  co_await a;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-28 12:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 12:52 [gcc r12-8309] c++, coroutines: Account for overloaded promise return_value() [PR105301] Iain D Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).