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

Conversation

Rajveer100
Copy link
Member

Resolves Issue #78754

@Rajveer100 Rajveer100 requested a review from a team as a code owner February 1, 2024 09:32
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 1, 2024

@llvm/pr-subscribers-libcxx

Author: Rajveer Singh Bharadwaj (Rajveer100)

Changes

Resolves Issue #78754


Full diff: https://github.com/llvm/llvm-project/pull/80261.diff

2 Files Affected:

  • (modified) libcxx/include/scoped_allocator (+2-2)
  • (modified) libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp (+8-1)
diff --git a/libcxx/include/scoped_allocator b/libcxx/include/scoped_allocator
index 6078906e92248..cfa2efe41456a 100644
--- a/libcxx/include/scoped_allocator
+++ b/libcxx/include/scoped_allocator
@@ -477,8 +477,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 2a9d7052eb655..d8135c6e7a1e7 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
@@ -107,13 +107,20 @@ int main(int, char**)
         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;
 }

Copy link

github-actions bot commented Feb 1, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Rajveer100 Rajveer100 force-pushed the branch-for-issue-78754 branch 2 times, most recently from d01c6f0 to eafa597 Compare February 1, 2024 09:46
@Rajveer100 Rajveer100 force-pushed the branch-for-issue-78754 branch from eafa597 to 91817ba Compare February 2, 2024 09:57
@mordante
Copy link
Member

mordante commented Feb 4, 2024

This seems like a duplicate of #80020 is that correct?

@Rajveer100
Copy link
Member Author

Rajveer100 commented Feb 5, 2024

This seems like a duplicate of #80020 is that correct?

While it's for the same issue, the approach to resolve differs.

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach better than mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants