Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LWG-4119 generator::promise_type::yield_value(ranges::elements_of<R, Alloc>)'s nested generator may be ill-formed #5220

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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