Skip to content

Commit

Permalink
Implement LWG-4119 `generator::promise_type::yield_value(ranges::elem…
Browse files Browse the repository at this point in the history
…ents_of<R, Alloc>)`'s nested `generator` may be ill-formed (microsoft#5220)

Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
frederick-vs-ja and StephanTLavavej authored Jan 14, 2025
1 parent 4119eb8 commit ba284eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions stl/inc/generator
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,10 @@ namespace _Gen_detail {
template <_RANGES input_range _Rng, class _Alloc>
requires convertible_to<_RANGES range_reference_t<_Rng>, _Yielded>
_NODISCARD auto yield_value(_RANGES elements_of<_Rng, _Alloc> _Elem) {
using _Vty = _RANGES range_value_t<_Rng>;
using _Nested_awaitable = _Nested_awaitable_provider<_Yielded, _Vty, _Alloc>::_Awaitable;
using _Nested_awaitable = _Nested_awaitable_provider<_Yielded, void, _Alloc>::_Awaitable;

auto _Lambda = [](allocator_arg_t, _Alloc, _RANGES iterator_t<_Rng> _It,
const _RANGES sentinel_t<_Rng> _Se) -> generator<_Yielded, _Vty, _Alloc> {
const _RANGES sentinel_t<_Rng> _Se) -> generator<_Yielded, void, _Alloc> {
for (; _It != _Se; ++_It) {
co_yield static_cast<_Yielded>(*_It);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P2502R2_generator_promise/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <memory_resource>
#include <new>
#include <ranges>
#include <span>
#include <string>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -226,6 +227,15 @@ struct Holder {
struct Incomplete;
#endif // ^^^ no workaround ^^^

#if !(defined(__clang__) && defined(_M_IX86)) // TRANSITION, LLVM-56507
// Also test LWG-4119:
// "generator::promise_type::yield_value(ranges::elements_of<R, Alloc>)'s nested generator may be ill-formed"
generator<span<int>> test_lwg_4119() { // COMPILE-ONLY
vector<vector<int>> v;
co_yield ranges::elements_of(v);
}
#endif // ^^^ no workaround ^^^

int main() {
test_with_type<int>();
test_with_type<float>();
Expand Down

0 comments on commit ba284eb

Please sign in to comment.