diff options
author | Jason Merrill <jason@redhat.com> | 2023-03-15 17:02:15 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-03-16 07:58:30 -0400 |
commit | d0ed0690f1e86621a5cb62eec1d144036feb16f8 (patch) | |
tree | a3b71fc7d8d1f8039392fe63d97e6d06d7f2a5b8 /gcc/cp | |
parent | 46c4be98d1e759a406069487e5dbaad0346e7e7d (diff) | |
download | gcc-d0ed0690f1e86621a5cb62eec1d144036feb16f8.zip gcc-d0ed0690f1e86621a5cb62eec1d144036feb16f8.tar.gz gcc-d0ed0690f1e86621a5cb62eec1d144036feb16f8.tar.bz2 |
c++: co_await and move-only type [PR105406]
Here we were building a temporary MoveOnlyAwaitable to hold the result of
evaluating 'o', but since 'o' is an lvalue we should build a reference
instead.
PR c++/105406
gcc/cp/ChangeLog:
* coroutines.cc (build_co_await): Handle lvalue 'o'.
gcc/testsuite/ChangeLog:
* g++.dg/coroutines/co-await-moveonly1.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/coroutines.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 7f8cbc3..a2189e4 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -1024,9 +1024,13 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind) } else { - e_proxy = get_awaitable_var (suspend_kind, o_type); + tree p_type = o_type; + if (glvalue_p (o)) + p_type = cp_build_reference_type (p_type, !lvalue_p (o)); + e_proxy = get_awaitable_var (suspend_kind, p_type); o = cp_build_modify_expr (loc, e_proxy, INIT_EXPR, o, tf_warning_or_error); + e_proxy = convert_from_reference (e_proxy); } /* I suppose we could check that this is contextually convertible to bool. */ @@ -1120,6 +1124,9 @@ build_co_await (location_t loc, tree a, suspend_point_kind suspend_kind) } TREE_VEC_ELT (awaiter_calls, 2) = awrs_call; /* await_resume(). */ + if (REFERENCE_REF_P (e_proxy)) + e_proxy = TREE_OPERAND (e_proxy, 0); + tree await_expr = build5_loc (loc, CO_AWAIT_EXPR, TREE_TYPE (TREE_TYPE (awrs_func)), a, e_proxy, o, awaiter_calls, |