From 341d3a59999dec56f51804a5356b2e38256ab55c Mon Sep 17 00:00:00 2001 From: Rajveer Singh Bharadwaj Date: Mon, 5 Feb 2024 22:11:36 +0530 Subject: [libc++] Fix ambiguity when using std::scoped_allocator constructor (#80261) Fixes #78754 --- libcxx/include/scoped_allocator | 5 ++--- .../allocator.adaptor/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 6078906..1626453 100644 --- a/libcxx/include/scoped_allocator +++ b/libcxx/include/scoped_allocator @@ -476,9 +476,8 @@ public: } private: - template ::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 _LIBCPP_HIDE_FROM_ABI void __construct(integral_constant, _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 a752dfd..1135ead 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(4)); assert((a.inner_allocator() == std::scoped_allocator_adaptor, A3>(A2(5), A3(6)))); } - // Test for LWG2782 { + // Test for LWG2782 static_assert(!std::is_convertible, A2>::value, ""); static_assert( !std::is_convertible< std::scoped_allocator_adaptor>, std::scoped_allocator_adaptor>>::value, ""); } + { + // Test construction from convertible-to-allocator types (https://github.com/llvm/llvm-project/issues/78754) + typedef std::scoped_allocator_adaptor, A1> A; + A a(A1(4), A1(5)); + assert(a.outer_allocator() == A1(4)); + assert(a.inner_allocator() == A1(5)); + } return 0; } -- cgit v1.1