在 2020/1/28 上午12:01, Nathan Sidwell 写道:
On 1/21/20 6:21 AM, JunMa wrote:
Hi
When test gcc with cppcoro, I find case like:

   int& awaitable::await_resume()
   auto x1 = co_await awaitable;
   decltype(auto) x2 = co_await awaitable;

Based on standard, typeof(x1) should be int, typeof(x2) is int&.
However, we get both x1 and x2 as int, this because we donot
consider indirect_ref which wrap await_resume call expression
(convert_from_reference), and it is invoked into type deduction
of auto and decltype(auto).

This patch wrap co_await expression with indirect_ref which should be
same with await_resume expression, and it sink await_resume expression
to real call_expr when replace co_await expression. it fix type deduction
of auto and decltype(auto) in coroutine.

Bootstrap and test on X86_64, is it OK?

+  /* Wrap co_await_expr.  */
+  if (TREE_CODE (awrs_call) == INDIRECT_REF)
+    await_expr = build1_loc (loc, INDIRECT_REF, TREE_TYPE (awrs_call),
+                 await_expr);

I think all you want here is:
  await_expr = convert_from_reference (await_expr);

Thanks, I'll update it.

Regards
JunMa

Regards
JunMa

gcc/cp
2020-01-21  Jun Ma <ju...@linux.alibaba.com>

         * coroutines.cc (build_co_await): Wrap co_await with
         indirect_ref when needed.
         (co_await_expander):  Sink to call_expr if await_resume
         is wrapped by indirect_ref.

gcc/testsuite
2020-01-21  Jun Ma <ju...@linux.alibaba.com>

         * g++.dg/coroutines/co-await-14-return-ref-to-auto.C: Add label.



Reply via email to