diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2020-02-04 09:36:30 +0000 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2020-02-04 09:37:18 +0000 |
commit | 5bc9d2f5ed4c39a7cad74db34e2bb125e012fa60 (patch) | |
tree | 037d790615997f3e62038b01203bec37b3b772a6 | |
parent | 5f0653a8b75a5ad5a5405a27dd92d3a5759eed4c (diff) | |
download | gcc-5bc9d2f5ed4c39a7cad74db34e2bb125e012fa60.zip gcc-5bc9d2f5ed4c39a7cad74db34e2bb125e012fa60.tar.gz gcc-5bc9d2f5ed4c39a7cad74db34e2bb125e012fa60.tar.bz2 |
coroutines: Prevent repeated error messages for missing promise.
If the user's coroutine return type omits the mandatory promise
type then we will currently restate that error each time we see
a coroutine keyword, which doesn't provide any new information.
This suppresses all but the first instance in each coroutine.
gcc/cp/ChangeLog:
2020-02-04 Iain Sandoe <iain@sandoe.co.uk>
* coroutines.cc (find_promise_type): Delete unused forward
declaration.
(struct coroutine_info): Add a bool for no promise type error.
(coro_promise_type_found_p): Only emit the error for a missing
promise once in each affected coroutine.
gcc/testsuite/ChangeLog:
2020-02-04 Iain Sandoe <iain@sandoe.co.uk>
* g++.dg/coroutines/coro-missing-promise.C: New test.
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/coroutines.cc | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/coroutines/coro-missing-promise.C | 20 |
4 files changed, 37 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8b35213..ab63ec7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2020-02-04 Iain Sandoe <iain@sandoe.co.uk> + + * coroutines.cc (find_promise_type): Delete unused forward + declaration. + (struct coroutine_info): Add a bool for no promise type error. + (coro_promise_type_found_p): Only emit the error for a missing + promise once in each affected coroutine. + 2020-02-03 Jason Merrill <jason@redhat.com> PR c++/66477 diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 8a0ce38..d5ff675 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -33,7 +33,6 @@ along with GCC; see the file COPYING3. If not see #include "gcc-rich-location.h" #include "hash-map.h" -static tree find_promise_type (tree); static bool coro_promise_type_found_p (tree, location_t); /* GCC C++ coroutines implementation. @@ -93,6 +92,7 @@ struct GTY((for_user)) coroutine_info function into a coroutine. */ /* Flags to avoid repeated errors for per-function issues. */ bool coro_ret_type_error_emitted; + bool coro_promise_error_emitted; }; struct coroutine_info_hasher : ggc_ptr_hash<coroutine_info> @@ -460,7 +460,10 @@ coro_promise_type_found_p (tree fndecl, location_t loc) /* If we don't find it, punt on the rest. */ if (coro_info->promise_type == NULL_TREE) { - error_at (loc, "unable to find the promise type for this coroutine"); + if (!coro_info->coro_promise_error_emitted) + error_at (loc, "unable to find the promise type for" + " this coroutine"); + coro_info->coro_promise_error_emitted = true; return false; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 06dba78..8e24530 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-02-04 Iain Sandoe <iain@sandoe.co.uk> + + * g++.dg/coroutines/coro-missing-promise.C: New test. + 2020-02-04 Richard Biener <rguenther@suse.de> PR tree-optimization/91123 diff --git a/gcc/testsuite/g++.dg/coroutines/coro-missing-promise.C b/gcc/testsuite/g++.dg/coroutines/coro-missing-promise.C new file mode 100644 index 0000000..3fc21a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/coro-missing-promise.C @@ -0,0 +1,20 @@ +// { dg-additional-options "-fsyntax-only -w" } + +#include "coro.h" + +// Diagnose completely missing promise. + +// { dg-error {no type named 'promise_type' in 'struct NoPromiseHere'} "" { target *-*-* } 0 } + +struct NoPromiseHere { + coro::coroutine_handle<> handle; + NoPromiseHere () : handle (nullptr) {} + NoPromiseHere (coro::coroutine_handle<> handle) : handle (handle) {} +}; + +NoPromiseHere +bar () +{ + co_yield 22; // { dg-error {unable to find the promise type for this coroutine} } + co_return 0; +} |