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

            Bug ID: 95519
           Summary: [coroutines] non-functions for
                    promise_type::return_void not supported
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruck.michael at gmail dot com
  Target Milestone: ---

The standard only requires certain expressions e.g. "p.return_void()", not
specifically functions. return_void is the only one I tested, presumably this
applies to more.

The example uses a struct with operator() and a function pointer.
Both work on clang.

https://gcc.godbolt.org/z/oW8eQ3


#ifndef __clang__
#include <coroutine>
#else
#include <experimental/coroutine>
namespace std { using namespace experimental; }
#endif

#include <cstdio>

struct rv
{
    void operator ()(){
        printf("call to operator\n");
    }
};

struct pt
{
    using handle_t = std::coroutine_handle<pt>;
    auto get_return_object() noexcept { return handle_t::from_promise(*this); }

    std::suspend_never initial_suspend() const noexcept { return {}; }
    std::suspend_never final_suspend() const noexcept { return {}; }
    //void return_void() const noexcept { printf("call to function\n"); }

    // error 1
    rv return_void;
    // error 2
    //static constexpr auto return_void = []{ printf("call to lambda\n");};
    void unhandled_exception() const noexcept {}
};

template <> struct std::coroutine_traits<pt::handle_t>
    { using promise_type = pt; };

static pt::handle_t foo()
{ 
    co_return;
}

int main()
{
    foo();
}
---
<source>: In function 'pt::handle_t foo()':
<source>:38:5: error: call to non-function 'pt::return_void'
   38 |     co_return;
      |     ^~~~~~~~~
<source>:39:1: error: call to non-function 'pt::return_void'
   39 | }
      | ^

Reply via email to