Skip to content

Commit 0194113

Browse files
burblebeetkoeppe
authored andcommitted
LWG3460 Unimplementable noop_coroutine_handle guarantees
For clarification, "returns the same value" was augmented to "returns the same non-null value", on suggestion of and with review by LWG members.
1 parent c30374c commit 0194113

File tree

1 file changed

+72
-5
lines changed

1 file changed

+72
-5
lines changed

source/support.tex

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,18 +5137,35 @@
51375137
};
51385138

51395139
template<class Promise>
5140-
struct coroutine_handle : coroutine_handle<>
5140+
struct coroutine_handle
51415141
{
51425142
// \ref{coroutine.handle.con}, construct/reset
5143-
using coroutine_handle<>::coroutine_handle;
5143+
constexpr coroutine_handle() noexcept;
5144+
constexpr coroutine_handle(nullptr_t) noexcept;
51445145
static coroutine_handle from_promise(Promise&);
51455146
coroutine_handle& operator=(nullptr_t) noexcept;
51465147

51475148
// \ref{coroutine.handle.export.import}, export/import
5149+
constexpr void* address() const noexcept;
51485150
static constexpr coroutine_handle from_address(void* addr);
51495151

5152+
// \ref{coroutine.handle.conv}, conversion
5153+
constexpr operator coroutine_handle<>() const noexcept;
5154+
5155+
// \ref{coroutine.handle.observers}, observers
5156+
constexpr explicit operator bool() const noexcept;
5157+
bool done() const;
5158+
5159+
// \ref{coroutine.handle.resumption}, resumption
5160+
void operator()() const;
5161+
void resume() const;
5162+
void destroy() const;
5163+
51505164
// \ref{coroutine.handle.promise}, promise access
51515165
Promise& promise() const;
5166+
5167+
private:
5168+
void* ptr; // \expos
51525169
};
51535170
}
51545171
\end{codeblock}
@@ -5157,8 +5174,12 @@
51575174
An object of type
51585175
\tcode{coroutine_handle<T>} is called a \term{coroutine handle}
51595176
and can be used to refer to a suspended or executing coroutine.
5160-
A default-constructed \tcode{coroutine_handle} object does not refer to any
5177+
A \tcode{coroutine_handle} object whose
5178+
member \tcode{address()} returns a null pointer value
5179+
does not refer to any
51615180
coroutine.
5181+
Two \tcode{coroutine_handle} objects refer to the same coroutine
5182+
if and only if their member \tcode{address()} returns the same non-null value.
51625183

51635184
\pnum
51645185
If a program declares an explicit or partial specialization of
@@ -5212,6 +5233,19 @@
52125233
\tcode{*this}.
52135234
\end{itemdescr}
52145235

5236+
\rSec3[coroutine.handle.conv]{Conversion}
5237+
5238+
\indexlibrarymember{operator coroutine_handle<>}{coroutine_handle}%
5239+
\begin{itemdecl}
5240+
constexpr operator coroutine_handle<>() const noexcept;
5241+
\end{itemdecl}
5242+
5243+
\begin{itemdescr}
5244+
\pnum
5245+
\effects
5246+
Equivalent to: \tcode{return coroutine_handle<>::from_address(address());}
5247+
\end{itemdescr}
5248+
52155249
\rSec3[coroutine.handle.export.import]{Export/import}
52165250

52175251
\indexlibrarymember{address}{coroutine_handle}%
@@ -5228,13 +5262,29 @@
52285262
\indexlibrarymember{from_address}{coroutine_handle}%
52295263
\begin{itemdecl}
52305264
static constexpr coroutine_handle<> coroutine_handle<>::from_address(void* addr);
5265+
\end{itemdecl}
5266+
5267+
\begin{itemdescr}
5268+
\pnum
5269+
\expects
5270+
\tcode{addr} was obtained via a prior call to \tcode{address}
5271+
on an object whose type is a specialization of \tcode{coroutine_handle}.
5272+
5273+
\pnum
5274+
\ensures
5275+
\tcode{from_address(address()) == *this}.
5276+
\end{itemdescr}
5277+
5278+
\indexlibrarymember{from_address}{coroutine_handle}%
5279+
\begin{itemdecl}
52315280
static constexpr coroutine_handle<Promise> coroutine_handle<Promise>::from_address(void* addr);
52325281
\end{itemdecl}
52335282

52345283
\begin{itemdescr}
52355284
\pnum
52365285
\expects
5237-
\tcode{addr} was obtained via a prior call to \tcode{address}.
5286+
\tcode{addr} was obtained via a prior call to \tcode{address}
5287+
on an object of type \cv \tcode{coroutine_handle<Promise>}.
52385288

52395289
\pnum
52405290
\ensures
@@ -5397,8 +5447,11 @@
53975447
\begin{codeblock}
53985448
namespace std {
53995449
template<>
5400-
struct coroutine_handle<noop_coroutine_promise> : coroutine_handle<>
5450+
struct coroutine_handle<noop_coroutine_promise>
54015451
{
5452+
// \ref{coroutine.handle.noop.conv}, conversion
5453+
constexpr operator coroutine_handle<>() const noexcept;
5454+
54025455
// \ref{coroutine.handle.noop.observers}, observers
54035456
constexpr explicit operator bool() const noexcept;
54045457
constexpr bool done() const noexcept;
@@ -5415,10 +5468,24 @@
54155468
constexpr void* address() const noexcept;
54165469
private:
54175470
coroutine_handle(@\unspec@);
5471+
void* ptr; // \expos
54185472
};
54195473
}
54205474
\end{codeblock}
54215475

5476+
\rSec4[coroutine.handle.noop.conv]{Conversion}
5477+
5478+
\indexlibrarymember{operator coroutine_handle<>}{coroutine_handle<noop_coroutine_promise>}%
5479+
\begin{itemdecl}
5480+
constexpr operator coroutine_handle<>() const noexcept;
5481+
\end{itemdecl}
5482+
5483+
\begin{itemdescr}
5484+
\pnum
5485+
\effects
5486+
Equivalent to: \tcode{return coroutine_handle<>::from_address(address());}
5487+
\end{itemdescr}
5488+
54225489
\rSec4[coroutine.handle.noop.observers]{Observers}
54235490

54245491
\indexlibrarymember{operator bool}{coroutine_handle<noop_coroutine_promise>}%

0 commit comments

Comments
 (0)