}
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. */
}
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,
--- /dev/null
+// PR c++/105406
+// { dg-do compile { target c++20 } }
+
+#include <coroutine>
+#include <exception>
+
+// A move-only awaitable
+class MoveOnlyAwaitable {
+public:
+ MoveOnlyAwaitable() = default;
+ MoveOnlyAwaitable(MoveOnlyAwaitable &&) = default;
+ MoveOnlyAwaitable &operator=(MoveOnlyAwaitable &&) = default;
+
+ MoveOnlyAwaitable(const MoveOnlyAwaitable &) = delete;
+ MoveOnlyAwaitable &operator=(const MoveOnlyAwaitable &) = delete;
+
+ bool await_ready() const noexcept { return false; }
+ void await_suspend(std::coroutine_handle<>) noexcept {}
+ void await_resume() {}
+};
+
+struct task {
+ struct promise_type {
+ auto initial_suspend() const { return std::suspend_never{}; }
+ auto final_suspend() const noexcept { return std::suspend_never(); }
+ auto get_return_object() { return task{}; }
+ void return_void() {}
+ void unhandled_exception() {}
+
+ template<typename T>
+ T &&await_transform(T &&t) {
+ return static_cast<T &&>(t);
+ }
+
+
+ };
+
+ bool await_ready() const { return false; }
+ void await_suspend(std::coroutine_handle<> awaiter) {}
+ void await_resume() {}
+};
+
+task myCoroutine() {
+ // GCC: OK
+ // clang: OK
+ {
+ co_await MoveOnlyAwaitable();
+ }
+ // GCC: OK
+ // clang: OK
+ {
+ auto moveonly = MoveOnlyAwaitable();
+ co_await std::move(moveonly);
+ }
+
+ // GCC <= 11.2: OK
+ // GCC 11.3:ERROR: error: use of deleted function 'MoveOnlyAwaitable::MoveOnlyAwaitable(const MoveOnlyAwaitable&)
+ // clang: OK
+ {
+ auto moveonly = MoveOnlyAwaitable();
+ co_await moveonly;
+ }
+}