[C++ coroutines 5/7, v3] Standard library header.

Jonathan Wakely jwakely@redhat.com
Thu Jan 9 21:21:00 GMT 2020


On 09/01/20 19:43 +0000, Iain Sandoe wrote:
>Hi Jonathan,
>
>thanks for the review - hopefully the attached addresses both those
>and the whitespace differences we discussed off-line.
>
>I’m attaching the header as a textfile since it’s a new one, perhaps
>that will make it easier to review the whitespace stuff.
>
>thanks
>Iain
>
>Jonathan Wakely <jwakely@redhat.com> wrote:
>
>> On 09/01/20 12:39 +0000, Iain Sandoe wrote:
>
>>> +#ifndef _GLIBCXX_EXPERIMENTAL_COROUTINE
>>> +#define _GLIBCXX_EXPERIMENTAL_COROUTINE 1
>>
>> Did you mean to leave EXPERIMENTAL in this macro?
>no, dropped.
>>>
>>> +  template <typename _R, typename...> struct coroutine_traits
>>
>> _R isn't in our list of identifiers to avoid, but it's uncomfortably
>> close to some of them. We generally try to avoid single-letter names.
>> Please use something like _Ret or _Res instead.
>
>used “_Result".
>
>>> \+    constexpr coroutine_handle (decltype (nullptr) __h) noexcept
>>
>> std::nullptr_t is defined in <bits/c++config.h> so you could use that
>> here.
>done.
>
>>> +    {}
>>
>> New line after this function body please.
>
>I’ve been through an added a newline after each body.
>
>>> +    coroutine_handle &operator= (decltype (nullptr)) noexcept
>>
>> Libstdc++ coding standards differ from the rest of GCC. We group the
>> ptr-declarator with the type, not the name, and there's no space
>> before the parens, so:
>>
>>    coroutine_handle& operator=(nullptr_t) noexcept
>
>Whitespace fixes applied throughout.
>
>>> +} // namespace std_GLIBCXX_VISIBILITY(default)
>>
>> No need for the _GLIBCXX... part here.
>
>indeed, that was a typo.
>

>// <coroutine> -*- C++ -*-
>
>// Copyright (C) 2019-2020 Free Software Foundation, Inc.
>//
>// This file is part of the GNU ISO C++ Library.  This library is free
>// software; you can redistribute it and/or modify it under the
>// terms of the GNU General Public License as published by the
>// Free Software Foundation; either version 3, or (at your option)
>// any later version.
>
>// This library is distributed in the hope that it will be useful,
>// but WITHOUT ANY WARRANTY; without even the implied warranty of
>// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>// GNU General Public License for more details.
>
>// Under Section 7 of GPL version 3, you are granted additional
>// permissions described in the GCC Runtime Library Exception, version
>// 3.1, as published by the Free Software Foundation.
>
>// You should have received a copy of the GNU General Public License and
>// a copy of the GCC Runtime Library Exception along with this program;
>// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
>// <http://www.gnu.org/licenses/>.
>
>/** @file include/coroutine
> *  This is a Standard C++ Library header.
> */
>
>#ifndef _GLIBCXX_COROUTINE
>#define _GLIBCXX_COROUTINE 1
>
>#pragma GCC system_header
>
>// It is very likely that earlier versions would work, but they are untested.
>#if __cplusplus >= 201402L
>
>#include <bits/c++config.h>
>
>/**
> * @defgroup coroutines Coroutines
> *
> * Components for supporting coroutine implementations.
> */
>
>#if __cplusplus > 201703L && __cpp_impl_three_way_comparison >= 201907L
>#  include <compare>
>#  define _COROUTINES_USE_SPACESHIP 1
>#else
>#  include <bits/stl_function.h> // for std::less
>#  define _COROUTINES_USE_SPACESHIP 0
>#endif
>
>namespace std _GLIBCXX_VISIBILITY (default)
>{
>  _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>#if __cpp_coroutines
>  inline namespace __n4835 {
>
>  // 17.12.2 coroutine traits
>  /// [coroutine.traits]
>  /// [coroutine.traits.primary]
>  template <typename _Result, typename...>
>    struct coroutine_traits
>    {
>       using promise_type = typename _Result::promise_type;
>    };
>
>  // 17.12.3 Class template coroutine_handle
>  /// [coroutine.handle]
>  template <typename _Promise = void>
>    struct coroutine_handle;
>
>  template <> struct
>    coroutine_handle<void>
>    {
>    public:
>      // 17.12.3.1, construct/reset
>      constexpr coroutine_handle() noexcept : _M_fr_ptr(0) {}
>
>      constexpr coroutine_handle(std::nullptr_t __h) noexcept
>	: _M_fr_ptr(__h)
>      {}
>
>      coroutine_handle& operator=(std::nullptr_t) noexcept
>      {
>	_M_fr_ptr = nullptr;
>	return *this;
>      }
>
>    public:
>      // 17.12.3.2, export/import
>      constexpr void* address() const noexcept { return _M_fr_ptr; }
>
>      constexpr static coroutine_handle from_address(void* __a) noexcept
>      {
>	coroutine_handle __self;
>	__self._M_fr_ptr = __a;
>	return __self;
>      }
>
>    public:
>      // 17.12.3.3, observers
>      constexpr explicit operator bool() const noexcept
>      {
>	return bool(_M_fr_ptr);
>      }
>
>      bool done() const noexcept { return __builtin_coro_done(_M_fr_ptr); }
>
>      // 17.12.3.4, resumption
>      void operator()() const { resume(); }
>
>      void resume() const { __builtin_coro_resume(_M_fr_ptr); }
>
>      void destroy() const { __builtin_coro_destroy(_M_fr_ptr); }
>
>    protected:
>      void* _M_fr_ptr;
>  };
>
>  // 17.12.3.6 Comparison operators
>  /// [coroutine.handle.compare]
>  constexpr bool operator==(coroutine_handle<> __a,
>			    coroutine_handle<> __b) noexcept
>  {
>    return __a.address() == __b.address();
>  }
>
>#if _COROUTINES_USE_SPACESHIP
>  constexpr strong_ordering
>  operator<=>(coroutine_handle<> __a, coroutine_handle<> __b) noexcept;

I think this needs to be defined, not just declared:

   { return std::compare_three_way()(__a.address(), __b.address()); }


OK for trunk (assuming it still works with that change).




More information about the Libstdc++ mailing list