public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-6357] libstdc++: Fix resolution of LWG 4016 for std::ranges::to [PR112876]
@ 2023-12-09 14:06 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-12-09 14:06 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:a314edee2490259d7f7caec8eef77846bcdb608b

commit r14-6357-ga314edee2490259d7f7caec8eef77846bcdb608b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Dec 8 13:47:04 2023 +0000

    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:
---
 libstdc++-v3/include/std/ranges             | 10 +++-------
 libstdc++-v3/testsuite/std/ranges/conv/1.cc | 12 ++++++------
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index fb9df3d3e79..be8475c0cb1 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 b5f861dedb3..6d6a708ab64 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<typename T>
     requires (Kind <= Emplace)
     && requires(C& c, T&& t) { c.emplace(c.end(), std::forward<T>(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>(t));
+      c.emplace(pos, std::forward<T>(t));
     }
 
   template<typename T>
-    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>(t));
+      c.insert(pos, std::forward<T>(t));
     }
 
   // Required to satisfy reservable-container

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-12-09 14:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-09 14:06 [gcc r14-6357] libstdc++: Fix resolution of LWG 4016 for std::ranges::to [PR112876] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).