[libcxx-commits] [libcxx] [libc++] Fix ambiguity when using std::scoped_allocator constructor (PR #80261)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Feb 5 08:40:34 PST 2024
https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/80261
>From 91817ba6c53da071bd3811b63b10ec01e9df21da Mon Sep 17 00:00:00 2001
From: Rajveer <rajveer.developer at icloud.com>
Date: Thu, 1 Feb 2024 14:58:18 +0530
Subject: [PATCH 1/2] [libc++] Fix ambiguity when using std::scoped_allocator
constructor
Resolves Issue #78754
---
libcxx/include/scoped_allocator | 5 ++---
.../allocator.adaptor.cnstr/allocs.pass.cpp | 9 ++++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/scoped_allocator b/libcxx/include/scoped_allocator
index 6078906e922482..1626453a698ff4 100644
--- a/libcxx/include/scoped_allocator
+++ b/libcxx/include/scoped_allocator
@@ -476,9 +476,8 @@ public:
}
private:
- template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0>
- _LIBCPP_HIDE_FROM_ABI scoped_allocator_adaptor(_OuterA2&& __o, const inner_allocator_type& __i) _NOEXCEPT
- : base(std::forward<_OuterA2>(__o), __i) {}
+ _LIBCPP_HIDE_FROM_ABI explicit scoped_allocator_adaptor(outer_allocator_type&& __o, inner_allocator_type&& __i) _NOEXCEPT
+ : base(std::move(__o), std::move(__i)) {}
template <class _Tp, class... _Args>
_LIBCPP_HIDE_FROM_ABI void __construct(integral_constant<int, 0>, _Tp* __p, _Args&&... __args) {
diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
index a752dfd029effa..eda6eb97e69e53 100644
--- a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
+++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
@@ -104,13 +104,20 @@ int main(int, char**) {
assert(a.outer_allocator() == A1<int>(4));
assert((a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
}
- // Test for LWG2782
{
+ // Test for LWG2782
static_assert(!std::is_convertible<A1<int>, A2<int>>::value, "");
static_assert(
!std::is_convertible< std::scoped_allocator_adaptor<A1<int>>, std::scoped_allocator_adaptor<A2<int>>>::value,
"");
}
+ {
+ // Test construction from convertible-to-allocator types
+ typedef std::scoped_allocator_adaptor<A1<int>, A1<int>> A;
+ A a(A1<char>(4), A1<char>(5));
+ assert(a.outer_allocator() == A1<int>(4));
+ assert(a.inner_allocator() == A1<int>(5));
+ }
return 0;
}
>From e2806fffc345f491281f828f1446a6127311e267 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Mon, 5 Feb 2024 11:40:28 -0500
Subject: [PATCH 2/2] Update
libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
---
.../allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
index eda6eb97e69e53..1135eadbb95ff9 100644
--- a/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
+++ b/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp
@@ -112,7 +112,7 @@ int main(int, char**) {
"");
}
{
- // Test construction from convertible-to-allocator types
+ // Test construction from convertible-to-allocator types (https://github.com/llvm/llvm-project/issues/78754)
typedef std::scoped_allocator_adaptor<A1<int>, A1<int>> A;
A a(A1<char>(4), A1<char>(5));
assert(a.outer_allocator() == A1<int>(4));
More information about the libcxx-commits
mailing list