Skip to content

Commit 341d3a5

Browse files
authored
[libc++] Fix ambiguity when using std::scoped_allocator constructor (#80261)
Fixes #78754
1 parent 1ec2522 commit 341d3a5

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

libcxx/include/scoped_allocator

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,8 @@ public:
476476
}
477477

478478
private:
479-
template <class _OuterA2, __enable_if_t<is_constructible<outer_allocator_type, _OuterA2>::value, int> = 0>
480-
_LIBCPP_HIDE_FROM_ABI scoped_allocator_adaptor(_OuterA2&& __o, const inner_allocator_type& __i) _NOEXCEPT
481-
: base(std::forward<_OuterA2>(__o), __i) {}
479+
_LIBCPP_HIDE_FROM_ABI explicit scoped_allocator_adaptor(outer_allocator_type&& __o, inner_allocator_type&& __i) _NOEXCEPT
480+
: base(std::move(__o), std::move(__i)) {}
482481

483482
template <class _Tp, class... _Args>
484483
_LIBCPP_HIDE_FROM_ABI void __construct(integral_constant<int, 0>, _Tp* __p, _Args&&... __args) {

libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,20 @@ int main(int, char**) {
104104
assert(a.outer_allocator() == A1<int>(4));
105105
assert((a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
106106
}
107-
// Test for LWG2782
108107
{
108+
// Test for LWG2782
109109
static_assert(!std::is_convertible<A1<int>, A2<int>>::value, "");
110110
static_assert(
111111
!std::is_convertible< std::scoped_allocator_adaptor<A1<int>>, std::scoped_allocator_adaptor<A2<int>>>::value,
112112
"");
113113
}
114+
{
115+
// Test construction from convertible-to-allocator types (https://github.com/llvm/llvm-project/issues/78754)
116+
typedef std::scoped_allocator_adaptor<A1<int>, A1<int>> A;
117+
A a(A1<char>(4), A1<char>(5));
118+
assert(a.outer_allocator() == A1<int>(4));
119+
assert(a.inner_allocator() == A1<int>(5));
120+
}
114121

115122
return 0;
116123
}

0 commit comments

Comments
 (0)