From: Jonathan Wakely Date: Fri, 8 Dec 2023 13:47:04 +0000 (+0000) Subject: libstdc++: Fix resolution of LWG 4016 for std::ranges::to [PR112876] X-Git-Tag: basepoints/gcc-15~3782 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a314edee2490259d7f7caec8eef77846bcdb608b;p=thirdparty%2Fgcc.git libstdc++: Fix resolution of LWG 4016 for std::ranges::to [PR112876] What I implemented in r14-6199-g45630fbcf7875b does not match what I proposed for LWG 4016, and it imposes additional, unwanted requirements on the emplace and insert member functions of the container being populated. libstdc++-v3/ChangeLog: PR libstdc++/112876 * include/std/ranges (ranges::to): Do not try to use an iterator returned by the container's emplace or insert member functions. * testsuite/std/ranges/conv/1.cc (Cont4::emplace, Cont4::insert): Use the iterator parameter. Do not return an iterator. --- diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index fb9df3d3e79b..be8475c0cb1b 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -9300,14 +9300,10 @@ namespace __detail __c.emplace_back(*__it); else if constexpr (requires { __c.push_back(*__it); }) __c.push_back(*__it); + else if constexpr (requires { __c.emplace(__c.end(), *__it); }) + __c.emplace(__c.end(), *__it); else - { - auto __end = __c.end(); - if constexpr (requires { __c.emplace(__end, *__it); }) - __end = __c.emplace(__end, *__it); - else - __end = __c.insert(__end, *__it); - } + __c.insert(__c.end(), *__it); ++__it; } return __c; diff --git a/libstdc++-v3/testsuite/std/ranges/conv/1.cc b/libstdc++-v3/testsuite/std/ranges/conv/1.cc index b5f861dedb30..6d6a708ab64c 100644 --- a/libstdc++-v3/testsuite/std/ranges/conv/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/conv/1.cc @@ -236,19 +236,19 @@ struct Cont4 template requires (Kind <= Emplace) && requires(C& c, T&& t) { c.emplace(c.end(), std::forward(t)); } - typename C::iterator - emplace(typename C::iterator, T&& t) + void + emplace(typename C::iterator pos, T&& t) { kind = Emplace; - return c.emplace(c.end(), std::forward(t)); + c.emplace(pos, std::forward(t)); } template - typename C::iterator - insert(typename C::iterator, T&& t) + void + insert(typename C::iterator pos, T&& t) { kind = Insert; - return c.insert(c.end(), std::forward(t)); + c.insert(pos, std::forward(t)); } // Required to satisfy reservable-container