https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100187
Bug ID: 100187 Summary: ranges::search_n helper lambda misses forwarding return type Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: hewillk at gmail dot com Target Milestone: --- ranges_algo.h#L565: auto __value_comp = [&] <typename _Rp> (_Rp&& __arg) { return std::__invoke(__pred, std::forward<_Rp>(__arg), __value); }; __value_comp misses forwarding the return type (-> decltype(auto)) which made the following unnecessary failed: #include <algorithm> struct Bool { operator bool() { return true; }; Bool() = default; Bool(const Bool&) = delete; }; int main() { Bool b; std::vector v{1, 0}; std::ranges::search_n(v, 1, 1, [&](auto, auto) -> Bool& { return b; }); } https://godbolt.org/z/zjn8Gz3c5