[Bug c++/101149] New: Coroutine compiler error with ternary operator

victor.burckel at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jun 21 11:16:17 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101149

            Bug ID: 101149
           Summary: Coroutine compiler error with ternary operator
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: victor.burckel at gmail dot com
  Target Milestone: ---

Hello, 

I'm getting a compiler error when trying to use co_await expression in a
ternary operator:
> internal compiler error: in expand_expr_real_1, at expr.c:10285

See on godbolt https://godbolt.org/z/Wfva333cc

#include <coroutine>
#include <vector>
#include <string>

struct task {
  struct promise_type {
    auto initial_suspend() noexcept { return std::suspend_always{}; }
    auto final_suspend() noexcept { return std::suspend_always{}; }
    void return_value(int) {}
    task get_return_object() { return task{}; }
    void unhandled_exception() noexcept {}
  };

  ~task() noexcept {}

  bool await_ready() const noexcept { return false; }
  void await_suspend(std::coroutine_handle<>) noexcept {}
  int await_resume() noexcept { return 1; }
};

task f(int)
{
    co_return 1;
}

task g(bool b)
{
    auto result = b ? co_await f(1) : 2;
}


More information about the Gcc-bugs mailing list