@@ -1139,6 +1139,20 @@ maybe_warn_nodiscard (tree expr, impl_conv_void implicit)
}
}
+/* Converts the await-resume of a given co_await expr to void. This is useful
+ because the await-resume expression is the result of the entire
+ co_await, so discarding the result of a co_await is the same as discarding
+ the result of its await-resume expr. */
+
+void
+convert_co_await_to_void (tree expr, impl_conv_void implicit,
+ tsubst_flags_t complain)
+{
+ auto awr = co_await_get_resume_call (expr);
+ if (awr)
+ convert_to_void (awr, implicit, complain);
+}
+
/* When an expression is used in a void context, its value is discarded and
no lvalue-rvalue and similar conversions happen [expr.static.cast/4,
stmt.expr/1, expr.comma/1]. This permits dereferencing an incomplete type
@@ -1421,6 +1435,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
if (TREE_CODE (expr) == CALL_EXPR
&& (complain & tf_warning))
maybe_warn_nodiscard (expr, implicit);
+ else if (TREE_CODE (expr) == CO_AWAIT_EXPR)
+ convert_co_await_to_void (expr, implicit, complain);
}
break;
@@ -1503,12 +1519,8 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain)
break;
case CO_AWAIT_EXPR:
- {
- auto awr = co_await_get_resume_call (expr);
- if (awr)
- awr = convert_to_void (awr, implicit, complain);
- break;
- }
+ convert_co_await_to_void (expr, implicit, complain);
+ break;
default:;
}