https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118022
Bug ID: 118022
Summary: <generator>: _Copy_awaiter should explicitly construct
_Yielded_decvref
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: hewillk at gmail dot com
Target Milestone: ---
auto
yield_value(const _Yielded_deref& __val)
noexcept (is_nothrow_constructible_v<_Yielded_decvref,
const _Yielded_deref&>)
requires (is_rvalue_reference_v<_Yielded>
&& constructible_from<_Yielded_decvref,
const _Yielded_deref&>)
{ return _Copy_awaiter(__val, _M_bottom_value()); }
We should explicitly construct _Yielded_decvref, e.g. _Yielded_decvref(__val)
as constructible_from only guarantees such validity:
#include <generator>
struct O {
O() = default;
explicit O(const O&) = default;
};
std::generator<O&&> gen() {
const O o;
co_yield o;
}
https://godbolt.org/z/8W9zGhbeM