aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2020-06-27 08:54:39 +0100
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-17 13:15:08 -0300
commit1861354754940214d12b04de0685c6ebd35cf28f (patch)
tree563eea6c369602c9ea9f86197f0cb27d4ddfbd85 /gcc
parent10cb3ecbba198cc75108f916b22259b2a4545503 (diff)
downloadgcc-1861354754940214d12b04de0685c6ebd35cf28f.zip
gcc-1861354754940214d12b04de0685c6ebd35cf28f.tar.gz
gcc-1861354754940214d12b04de0685c6ebd35cf28f.tar.bz2
coroutines: Improve diagnostics for one allocator case.
If the user provides operator new and that is noexcept, this implies that it can fail with a null return. At that point, we expect to be able to call get_return_object_on_allocation_failure(). This diagnoses the case where such an operator new has been provided, but the g-r-o-o-a-f is either missing or unusable. gcc/cp/ChangeLog: * coroutines.cc (morph_fn_to_coro): Diagnose unavailable get_return_object_on_allocation_failure. gcc/testsuite/ChangeLog: * g++.dg/coroutines/coro-bad-grooaf-01-grooaf-expected.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/coroutines.cc4
-rw-r--r--gcc/testsuite/g++.dg/coroutines/coro-bad-grooaf-01-grooaf-expected.C14
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 6e723c4..8b8d00e 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -4041,6 +4041,10 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
else if (grooaf && !TYPE_NOTHROW_P (TREE_TYPE (func)))
error_at (fn_start, "%qE is provided by %qT but %qE is not marked"
" %<throw()%> or %<noexcept%>", grooaf, promise_type, nwname);
+ else if (!grooaf && TYPE_NOTHROW_P (TREE_TYPE (func)))
+ warning_at (fn_start, 0, "%qE is marked %<throw()%> or %<noexcept%> but"
+ " no usable %<get_return_object_on_allocation_failure%>"
+ " is provided by %qT ", nwname, promise_type);
}
else /* No operator new in the promise. */
{
diff --git a/gcc/testsuite/g++.dg/coroutines/coro-bad-grooaf-01-grooaf-expected.C b/gcc/testsuite/g++.dg/coroutines/coro-bad-grooaf-01-grooaf-expected.C
new file mode 100644
index 0000000..9fa3d64
--- /dev/null
+++ b/gcc/testsuite/g++.dg/coroutines/coro-bad-grooaf-01-grooaf-expected.C
@@ -0,0 +1,14 @@
+/* g-r-o-o-a-f would be expected, since we have a noexcept op new. */
+
+#define USE_FAILING_OP_NEW
+#include "coro1-allocators.h"
+
+int used_grooaf = 0;
+
+struct coro1
+f () noexcept // { dg-warning {'operator new' is marked 'throw\(\)' or 'noexcept' but no usable 'get_return_object_on_allocation_failure' is provided by 'std::__n4861::__coroutine_traits_impl<coro1, void>::promise_type' \{aka 'coro1::promise_type'\}} }
+{
+ PRINT ("coro1: about to return");
+ co_return;
+}
+