[libcxx-commits] [libcxx] [libc++] fixing missing forward declarations of uses_allocator_construction_args (PR #67044)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 22 05:21:17 PDT 2023


https://github.com/phyBrackets updated https://github.com/llvm/llvm-project/pull/67044

>From 88cc695ae88d014d1fce8ced1077cf96fe6928a1 Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Thu, 21 Sep 2023 22:52:42 +0530
Subject: [PATCH 1/6] forward declarations for
 __uses_allocator_construction_args

---
 .../__memory/uses_allocator_construction.h    | 38 ++++++++++++++++---
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/__memory/uses_allocator_construction.h b/libcxx/include/__memory/uses_allocator_construction.h
index a2e4f6e26f4b3af..b4e3b54bf39b8f7 100644
--- a/libcxx/include/__memory/uses_allocator_construction.h
+++ b/libcxx/include/__memory/uses_allocator_construction.h
@@ -53,6 +53,32 @@ __uses_allocator_construction_args(const _Alloc& __alloc, _Args&&... __args) noe
 }
 
 template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto
+__uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept;
+
+template <class _Pair, class _Alloc, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc&) noexcept;
+
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc&, _Up&&, _Vp&&) noexcept;
+
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto
+__uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair) noexcept;
+
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto
+__uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>& __pair) noexcept;
+
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto
+__uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pair) noexcept;
+
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+_LIBCPP_HIDE_FROM_ABI constexpr auto
+__uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>&& __pair) noexcept;
+
+template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(
     const _Alloc& __alloc, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept {
   return std::make_tuple(
@@ -71,12 +97,12 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(
           std::forward<_Tuple2>(__y)));
 }
 
-template <class _Pair, class _Alloc, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+template <class _Pair, class _Alloc, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(const _Alloc& __alloc) noexcept {
   return std::__uses_allocator_construction_args<_Pair>(__alloc, piecewise_construct, tuple<>{}, tuple<>{});
 }
 
-template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto
 __uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) noexcept {
   return std::__uses_allocator_construction_args<_Pair>(
@@ -87,7 +113,7 @@ __uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v)
 }
 
 #  if _LIBCPP_STD_VER >= 23
-template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto
 __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair) noexcept {
   return std::__uses_allocator_construction_args<_Pair>(
@@ -95,14 +121,14 @@ __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>& __pair
 }
 #  endif
 
-template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto
 __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>& __pair) noexcept {
   return std::__uses_allocator_construction_args<_Pair>(
       __alloc, piecewise_construct, std::forward_as_tuple(__pair.first), std::forward_as_tuple(__pair.second));
 }
 
-template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto
 __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pair) noexcept {
   return std::__uses_allocator_construction_args<_Pair>(
@@ -113,7 +139,7 @@ __uses_allocator_construction_args(const _Alloc& __alloc, pair<_Up, _Vp>&& __pai
 }
 
 #  if _LIBCPP_STD_VER >= 23
-template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
+template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int>>
 _LIBCPP_HIDE_FROM_ABI constexpr auto
 __uses_allocator_construction_args(const _Alloc& __alloc, const pair<_Up, _Vp>&& __pair) noexcept {
   return std::__uses_allocator_construction_args<_Pair>(

>From 529a21b5d82be019fed4e81af941778e90f4cb2a Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Fri, 22 Sep 2023 10:18:34 +0530
Subject: [PATCH 2/6] test coverage for the change

---
 .../uses_allocator_construction_args.pass.cpp          | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
index 739278e74ddab4f..e020400e7b85d68 100644
--- a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
@@ -118,6 +118,16 @@ constexpr bool test() {
     assert(std::get<2>(std::get<1>(ret)) == 3);
     assert(std::get<0>(std::get<2>(ret)) == 4);
   }
+  {
+    using nestedPairType = std::pair<std::pmr::string, std::pair<std::pmr::string, std::pmr::string>>;
+    std::pmr::polymorphic_allocator<nestedPairType> alloc;
+    std::same_as<std::tuple<std::piecewise_construct_t,
+                            std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&>,
+                            std::tuple<std::piecewise_construct_t,
+                                       std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&>,
+                                       std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&> >>> auto s =
+        test_uses_allocator_construction_args<nestedPairType>(alloc);
+  }
 #if TEST_STD_VER >= 23
   {
     std::pair p{3, 4};

>From a599a8d19abe17cc3517fa4c5afd957931b9d59e Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Fri, 22 Sep 2023 10:20:00 +0530
Subject: [PATCH 3/6] tests

---
 .../uses_allocator_construction_args.pass.cpp                   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
index e020400e7b85d68..e7c1c8b84c77308 100644
--- a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
@@ -125,7 +125,7 @@ constexpr bool test() {
                             std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&>,
                             std::tuple<std::piecewise_construct_t,
                                        std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&>,
-                                       std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&> >>> auto s =
+                                       std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&> >>> auto ret =
         test_uses_allocator_construction_args<nestedPairType>(alloc);
   }
 #if TEST_STD_VER >= 23

>From ec111bcdfc3bae2d2bdcf0e790cfb5182b545d46 Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Fri, 22 Sep 2023 12:10:31 +0530
Subject: [PATCH 4/6] missing header

---
 .../uses_allocator_construction_args.pass.cpp                    | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
index e7c1c8b84c77308..99160dd3a0e4919 100644
--- a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
@@ -18,6 +18,7 @@
 #include <memory>
 #include <tuple>
 #include <utility>
+#include <memory_resource>
 
 #include "common.h"
 #include "test_allocator.h"

>From a9d8eb0685b80a4c9084a16419872f81c604c585 Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Fri, 22 Sep 2023 12:55:11 +0530
Subject: [PATCH 5/6] update the test correctly

---
 .../uses_allocator_construction_args.pass.cpp      | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
index 99160dd3a0e4919..13a6d74bfc504d7 100644
--- a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
@@ -18,7 +18,6 @@
 #include <memory>
 #include <tuple>
 #include <utility>
-#include <memory_resource>
 
 #include "common.h"
 #include "test_allocator.h"
@@ -120,13 +119,14 @@ constexpr bool test() {
     assert(std::get<0>(std::get<2>(ret)) == 4);
   }
   {
-    using nestedPairType = std::pair<std::pmr::string, std::pair<std::pmr::string, std::pmr::string>>;
-    std::pmr::polymorphic_allocator<nestedPairType> alloc;
-    std::same_as<std::tuple<std::piecewise_construct_t,
-                            std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&>,
+    using nestedPairType = std::pair<std::string, std::pair<std::string, std::string>>;
+    std::allocator<nestedPairType> alloc;
+
+    [[maybe_unused]] std::same_as<std::tuple<std::piecewise_construct_t,
+                            std::tuple<const std::allocator<nestedPairType>&>,
                             std::tuple<std::piecewise_construct_t,
-                                       std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&>,
-                                       std::tuple<const std::pmr::polymorphic_allocator<nestedPairType>&> >>> auto ret =
+                                       std::tuple<const std::allocator<nestedPairType>&>,
+                                       std::tuple<const std::allocator<nestedPairType>&> >>> auto ret =
         test_uses_allocator_construction_args<nestedPairType>(alloc);
   }
 #if TEST_STD_VER >= 23

>From 805a8c9bc71046fea387d00a2317aac563b23243 Mon Sep 17 00:00:00 2001
From: Shivam Kunwar <shivam.kunwar at kdab.com>
Date: Thu, 21 Sep 2023 22:52:42 +0530
Subject: [PATCH 6/6] forward declarations for
 __uses_allocator_construction_args

---
 .../allocator.uses/allocator.uses.construction/common.h       | 1 +
 .../uses_allocator_construction_args.pass.cpp                 | 4 +---
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/common.h b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/common.h
index 48b0fa85a8c2386..29da933e633263d 100644
--- a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/common.h
+++ b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/common.h
@@ -9,6 +9,7 @@
 #include "test_allocator.h"
 
 using Alloc = test_allocator<int>;
+using nestedPairType = std::pair<std::string, std::pair<std::string, std::string>>;
 
 enum class RefType {
   LValue,
diff --git a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
index 13a6d74bfc504d7..f9b09e632cbf2a6 100644
--- a/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
+++ b/libcxx/test/std/utilities/memory/allocator.uses/allocator.uses.construction/uses_allocator_construction_args.pass.cpp
@@ -30,6 +30,7 @@ constexpr decltype(auto) test_uses_allocator_construction_args(Args&&... args) {
 
 constexpr bool test() {
   Alloc a(12);
+  std::allocator<nestedPairType> alloc;
   {
     std::same_as<std::tuple<std::allocator_arg_t, const Alloc&>> auto ret =
         test_uses_allocator_construction_args<UsesAllocArgT>(a);
@@ -119,9 +120,6 @@ constexpr bool test() {
     assert(std::get<0>(std::get<2>(ret)) == 4);
   }
   {
-    using nestedPairType = std::pair<std::string, std::pair<std::string, std::string>>;
-    std::allocator<nestedPairType> alloc;
-
     [[maybe_unused]] std::same_as<std::tuple<std::piecewise_construct_t,
                             std::tuple<const std::allocator<nestedPairType>&>,
                             std::tuple<std::piecewise_construct_t,



More information about the libcxx-commits mailing list