Commit 289437aa by Iain Sandoe

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.

(cherry picked from commit 9c5ca11a33fa91345fe813d449ddc4a821fc72d5)
parent 11e1cfcf
...@@ -4053,6 +4053,10 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) ...@@ -4053,6 +4053,10 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
else if (grooaf && !TYPE_NOTHROW_P (TREE_TYPE (func))) else if (grooaf && !TYPE_NOTHROW_P (TREE_TYPE (func)))
error_at (fn_start, "%qE is provided by %qT but %qE is not marked" error_at (fn_start, "%qE is provided by %qT but %qE is not marked"
" %<throw()%> or %<noexcept%>", grooaf, promise_type, nwname); " %<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. */ else /* No operator new in the promise. */
{ {
......
/* 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment