jbaldwin / libcoro

C++20 coroutine library
Apache License 2.0
566 stars 57 forks source link

Fix awaitable concepts and remove unnecessary virtual destructor and support clang #187

Closed a858438680 closed 11 months ago

a858438680 commented 11 months ago

to co_await some object:

  1. If the promise type has member await_transform, the object is transformed to get the awaitable, otherwise the object is the awaitable type.
    • If the awaitable type has member operator co_await() that returns an awaiter, it is call to get the awaiter.
    • If there is a global operator co_await() that matches this awaitable type and returns an awaiter, then it is call to get the awaiter.
    • Otherwise the awaitable object should be an awaiter.
  2. co_await on the awaiter.

So the awaitable and awaitable_void concept in the include/coro/concepts/awaitable.hpp is wrong and cannot support all awaitable types. This pull request fixes this.

The sync_wait_task_promise_base is not used as a polymorphic base, so the virtual destructor is not needed. The pull request fixes this.

To support compilation using clang, the cmake files are changed. The fatal error when detecting clang compiler is canceled, and proper compile options are set.

To pass the tests, some tests themselves are changed for they used a temporary captured lambda object to create a coroutine. When the coroutine is resumed, the temporary lambda has already been destructed. So the captured value and references are move to the function parameter which will be saved on the coroutine frame.

The co_yield i++; in an example causes warning in clang, so it is changed into co_yield i; ++i;

jbaldwin commented 11 months ago

Great change, thanks for submitting the PR!