Skip to content

[libc++] Fix ambiguity when using std::scoped_allocator constructor #80261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions libcxx/include/scoped_allocator
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (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));
assert(a.inner_allocator() == A1<int>(5));
}

return 0;
}