]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix uses_allocator_construction args for cv pair (LWG 3677)
authorJonathan Wakely <jwakely@redhat.com>
Fri, 14 Oct 2022 13:25:48 +0000 (14:25 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 15 Oct 2022 20:17:48 +0000 (21:17 +0100)
The _Std_pair concept uses in <bits/uses_allocator_args.h> handles const
qualified pairs, but not volatile qualified. That's because it just uses
__is_pair which is specialized for const pairs.

This removes the partial specialization __is_pair<const pair<T,U>>, so
that __is_pair is now only true for cv-unqualified pairs. Then _Std_pair
needs to explicitly use remove_cv_t for the argument to __is_pair.

The other use of __is_pair is in map::insert(Pair&&) which doesn't want
to handle volatile so should just use remove_const_t.

libstdc++-v3/ChangeLog:

* include/bits/stl_map.h (map::insert(Pair&&)): Use
remove_const_t on argument to __is_pair.
* include/bits/stl_pair.h (__is_pair<const pair<T,U>>): Remove
partial specialization.
* include/bits/uses_allocator_args.h (_Std_pair): Use
remove_cv_t as per LWG 3677.
* testsuite/20_util/uses_allocator/lwg3677.cc: New test.

libstdc++-v3/include/bits/stl_map.h
libstdc++-v3/include/bits/stl_pair.h
libstdc++-v3/include/bits/uses_allocator_args.h
libstdc++-v3/testsuite/20_util/uses_allocator/lwg3677.cc [new file with mode: 0644]

index 9c2b0745673431b4b396ba27982170478838137e..83c579aaedcf1196ce4ea5f141eb372f78268f42 100644 (file)
@@ -847,7 +847,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        {
 #if __cplusplus >= 201703L
          using _P2 = remove_reference_t<_Pair>;
-         if constexpr (__is_pair<_P2>)
+         if constexpr (__is_pair<remove_const_t<_P2>>)
            if constexpr (is_same_v<allocator_type, allocator<value_type>>)
              if constexpr (__usable_key<typename _P2::first_type>)
                {
index d0f07b09d347c17e9561e9b092acb5130b12825c..195167019b768e0900668074ac0f8cf5a1b682a8 100644 (file)
@@ -889,9 +889,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Tp, typename _Up>
     inline constexpr bool __is_pair<pair<_Tp, _Up>> = true;
-
-  template<typename _Tp, typename _Up>
-    inline constexpr bool __is_pair<const pair<_Tp, _Up>> = true;
 #endif
 
   /// @cond undocumented
index ef5c4fffb709c12bcb745cab9cf2465cbb1dd335..77e48602aac2bb698952bb653cd023b4a4fac592 100644 (file)
@@ -44,7 +44,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _Tp>
-    concept _Std_pair = __is_pair<_Tp>;
+    concept _Std_pair = __is_pair<remove_cv_t<_Tp>>;
 
 /** @addtogroup allocators
  *  @{
diff --git a/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3677.cc b/libstdc++-v3/testsuite/20_util/uses_allocator/lwg3677.cc
new file mode 100644 (file)
index 0000000..649b98d
--- /dev/null
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++23" }
+// { dg-do run { target c++20 } }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+struct UsesAlloc
+{
+  using allocator_type = std::allocator<int>;
+
+  bool passed_alloc;
+
+  UsesAlloc(int) : passed_alloc(false) { }
+
+  UsesAlloc(int, std::allocator<int>) : passed_alloc(true) { }
+};
+
+using Pair = std::pair<UsesAlloc, int>;
+
+void
+test_const()
+{
+  std::allocator<int> a;
+  int i = 0;
+  auto p = std::make_obj_using_allocator<const Pair>(a, i, i);
+  VERIFY( p.first.passed_alloc );
+}
+
+void
+test_volatile()
+{
+  std::allocator<int> a;
+  int i = 0;
+  auto p = std::make_obj_using_allocator<volatile Pair>(a, i, i);
+  VERIFY( p.first.passed_alloc );
+}
+
+void
+test_const_volatile()
+{
+  std::allocator<int> a;
+  int i = 0;
+  auto p = std::make_obj_using_allocator<volatile Pair>(a, i, i);
+  VERIFY( p.first.passed_alloc );
+}
+
+int main()
+{
+  test_const();
+  test_volatile();
+  test_const_volatile();
+}