[libcxx-commits] [libcxx] 276ca87 - [libc++] Remove extension to support allocator<const T>

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 8 12:05:21 PST 2022


Author: Louis Dionne
Date: 2022-03-08T15:05:12-05:00
New Revision: 276ca87382b8f16a65bddac700202924228982f6

URL: https://github.com/llvm/llvm-project/commit/276ca87382b8f16a65bddac700202924228982f6
DIFF: https://github.com/llvm/llvm-project/commit/276ca87382b8f16a65bddac700202924228982f6.diff

LOG: [libc++] Remove extension to support allocator<const T>

This extension is a portability trap for users, since no other standard
library supports it. Furthermore, the Standard explicitly allows
implementations to reject std::allocator<cv T>, so allowing it is
really going against the current.

This was discovered in D120684: this extension required `const_cast`ing
in `__construct_range_forward`, a fishy bit of code that can be removed
if we don't support the extension anymore.

This is a re-application of dbc647643577, which was reverted in 9138666f5
because it broke std::shared_ptr<T const>. Tests have now been added and
we've made sure that std::shared_ptr<T const> wouldn't be broken in this
version.

Differential Revision: https://reviews.llvm.org/D120996

Added: 
    libcxx/test/libcxx/memory/allocator.cv.verify.cpp

Modified: 
    libcxx/docs/ReleaseNotes.rst
    libcxx/include/__memory/allocator.h
    libcxx/include/__memory/shared_ptr.h
    libcxx/include/memory
    libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
    libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
    libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
    libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp

Removed: 
    libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp
    libcxx/test/libcxx/memory/allocator_volatile.verify.cpp


################################################################################
diff  --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst
index d78549edb10cf..390beddd1ee21 100644
--- a/libcxx/docs/ReleaseNotes.rst
+++ b/libcxx/docs/ReleaseNotes.rst
@@ -74,6 +74,11 @@ API Changes
 - The C++14 function ``std::quoted(const char*)`` is no longer supported in
   C++03 or C++11 modes.
 
+- libc++ no longer supports containers of ``const``-qualified element type,
+  such as ``vector<const T>`` and ``list<const T>``. This used to be supported
+  as an extension. Likewise, ``std::allocator<const T>`` is no longer supported.
+  If you were using ``vector<const T>``, replace it with ``vector<T>`` instead.
+
 ABI Changes
 -----------
 

diff  --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index 915ff7c3a516a..4b5df0d17fcd9 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -37,17 +37,6 @@ class _LIBCPP_TEMPLATE_VIS allocator<void>
 
     template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
 };
-
-template <>
-class _LIBCPP_TEMPLATE_VIS allocator<const void>
-{
-public:
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const void*       pointer;
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const void*       const_pointer;
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const void        value_type;
-
-    template <class _Up> struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {typedef allocator<_Up> other;};
-};
 #endif
 
 // This class provides a non-trivial default constructor to the class that derives from it
@@ -80,6 +69,7 @@ template <class _Tp>
 class _LIBCPP_TEMPLATE_VIS allocator
     : private __non_trivial_if<!is_void<_Tp>::value, allocator<_Tp> >
 {
+    static_assert(!is_const<_Tp>::value, "std::allocator does not support const types");
     static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
 public:
     typedef size_t      size_type;
@@ -158,84 +148,6 @@ class _LIBCPP_TEMPLATE_VIS allocator
 #endif
 };
 
-template <class _Tp>
-class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
-    : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> >
-{
-    static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
-public:
-    typedef size_t      size_type;
-    typedef ptr
diff _t   
diff erence_type;
-    typedef const _Tp   value_type;
-    typedef true_type   propagate_on_container_move_assignment;
-    typedef true_type   is_always_equal;
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    allocator() _NOEXCEPT = default;
-
-    template <class _Up>
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    allocator(const allocator<_Up>&) _NOEXCEPT { }
-
-    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    const _Tp* allocate(size_t __n) {
-        if (__n > allocator_traits<allocator>::max_size(*this))
-            __throw_bad_array_new_length();
-        if (__libcpp_is_constant_evaluated()) {
-            return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp)));
-        } else {
-            return static_cast<const _Tp*>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
-        }
-    }
-
-    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
-    void deallocate(const _Tp* __p, size_t __n) {
-        if (__libcpp_is_constant_evaluated()) {
-            ::operator delete(const_cast<_Tp*>(__p));
-        } else {
-            _VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
-        }
-    }
-
-    // C++20 Removed members
-#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS)
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;
-    _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference;
-
-    template <class _Up>
-    struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
-        typedef allocator<_Up> other;
-    };
-
-    _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
-    const_pointer address(const_reference __x) const _NOEXCEPT {
-        return _VSTD::addressof(__x);
-    }
-
-    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_IN_CXX17
-    const _Tp* allocate(size_t __n, const void*) {
-        return allocate(__n);
-    }
-
-    _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT {
-        return size_type(~0) / sizeof(_Tp);
-    }
-
-    template <class _Up, class... _Args>
-    _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
-    void construct(_Up* __p, _Args&&... __args) {
-        ::new ((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
-    }
-
-    _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_INLINE_VISIBILITY
-    void destroy(pointer __p) {
-        __p->~_Tp();
-    }
-#endif
-};
-
 template <class _Tp, class _Up>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}

diff  --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 7401d3a891c1d..9d3e1c63ba25d 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -282,13 +282,15 @@ template <class _Tp, class _Alloc>
 struct __shared_ptr_emplace
     : __shared_weak_count
 {
+    using _TpAlloc = typename __allocator_traits_rebind<_Alloc, typename remove_cv<_Tp>::type>::type;
+    using _ControlBlockAlloc = typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type;
+
     template<class ..._Args>
     _LIBCPP_HIDE_FROM_ABI
     explicit __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
         : __storage_(_VSTD::move(__a))
     {
 #if _LIBCPP_STD_VER > 17
-        using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
         _TpAlloc __tmp(*__get_alloc());
         allocator_traits<_TpAlloc>::construct(__tmp, __get_elem(), _VSTD::forward<_Args>(__args)...);
 #else
@@ -305,7 +307,6 @@ struct __shared_ptr_emplace
 private:
     virtual void __on_zero_shared() _NOEXCEPT {
 #if _LIBCPP_STD_VER > 17
-        using _TpAlloc = typename __allocator_traits_rebind<_Alloc, _Tp>::type;
         _TpAlloc __tmp(*__get_alloc());
         allocator_traits<_TpAlloc>::destroy(__tmp, __get_elem());
 #else
@@ -314,7 +315,6 @@ struct __shared_ptr_emplace
     }
 
     virtual void __on_zero_shared_weak() _NOEXCEPT {
-        using _ControlBlockAlloc = typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type;
         using _ControlBlockPointer = typename allocator_traits<_ControlBlockAlloc>::pointer;
         _ControlBlockAlloc __tmp(*__get_alloc());
         __storage_.~_Storage();
@@ -643,8 +643,9 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr
     shared_ptr(auto_ptr<_Yp>&& __r)
         : __ptr_(__r.get())
     {
-        typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
-        __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
+        typedef allocator<typename remove_cv<_Yp>::type> _YpAlloc;
+        typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _YpAlloc> _CntrlBlk;
+        __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), _YpAlloc());
         __enable_weak_this(__r.get(), __r.get());
         __r.release();
     }
@@ -890,7 +891,7 @@ class _LIBCPP_SHARED_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS shared_ptr
     template <class _Yp, bool = is_function<_Yp>::value>
     struct __shared_ptr_default_allocator
     {
-        typedef allocator<_Yp> type;
+        typedef allocator<typename remove_cv<_Yp>::type> type;
     };
 
     template <class _Yp>
@@ -960,7 +961,7 @@ template<class _Tp, class ..._Args, class = __enable_if_t<!is_array<_Tp>::value>
 _LIBCPP_HIDE_FROM_ABI
 shared_ptr<_Tp> make_shared(_Args&& ...__args)
 {
-    return _VSTD::allocate_shared<_Tp>(allocator<_Tp>(), _VSTD::forward<_Args>(__args)...);
+    return _VSTD::allocate_shared<_Tp>(allocator<typename remove_cv<_Tp>::type>(), _VSTD::forward<_Args>(__args)...);
 }
 
 template<class _Tp, class _Up>

diff  --git a/libcxx/include/memory b/libcxx/include/memory
index 1fccdacdcf862..ea8ed0f9f361a 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -895,19 +895,17 @@ void __construct_range_forward(_Alloc& __a, _Iter __begin1, _Iter __end1, _Ptr&
 }
 
 template <class _Alloc, class _Source, class _Dest,
-          class _RawSource = typename remove_const<_Source>::type,
-          class _RawDest = typename remove_const<_Dest>::type,
           class =
     typename enable_if<
         is_trivially_copy_constructible<_Dest>::value &&
-        is_same<_RawSource, _RawDest>::value &&
+        is_same<typename remove_const<_Source>::type, _Dest>::value &&
         (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Dest*, _Source&>::value)
     >::type>
 _LIBCPP_INLINE_VISIBILITY
 void __construct_range_forward(_Alloc&, _Source* __begin1, _Source* __end1, _Dest*& __begin2) {
     ptr
diff _t _Np = __end1 - __begin1;
     if (_Np > 0) {
-        _VSTD::memcpy(const_cast<_RawDest*>(__begin2), __begin1, _Np * sizeof(_Dest));
+        _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Dest));
         __begin2 += _Np;
     }
 }

diff  --git a/libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp b/libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp
deleted file mode 100644
index 1ad505a76d3fb..0000000000000
--- a/libcxx/test/libcxx/containers/sequences/vector/const_value_type.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03
-
-// <vector>
-
-// vector<const int> v;  // an extension
-
-#include <vector>
-#include <type_traits>
-
-#include "test_macros.h"
-
-int main(int, char**)
-{
-    std::vector<const int> v = {1, 2, 3};
-
-  return 0;
-}

diff  --git a/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp b/libcxx/test/libcxx/memory/allocator.cv.verify.cpp
similarity index 78%
rename from libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
rename to libcxx/test/libcxx/memory/allocator.cv.verify.cpp
index 6fa7fe1b1aeda..6515d8ae765fd 100644
--- a/libcxx/test/libcxx/memory/allocator_volatile.verify.cpp
+++ b/libcxx/test/libcxx/memory/allocator.cv.verify.cpp
@@ -6,9 +6,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-// http://wg21.link/LWG2447 gives implementors freedom to reject volatile types in `std::allocator`.
+// http://wg21.link/LWG2447 gives implementors freedom to reject const or volatile types in `std::allocator`.
 
 #include <memory>
 
 std::allocator<volatile int> A1; // expected-error@*:* {{std::allocator does not support volatile types}}
-std::allocator<const volatile int> A2; // expected-error@*:* {{std::allocator does not support volatile types}}
+std::allocator<const int> A2; // expected-error@*:* {{std::allocator does not support const types}}

diff  --git a/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp b/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
index f9d67c065de85..69a4b8943caa6 100644
--- a/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
+++ b/libcxx/test/libcxx/memory/allocator_void.trivial.compile.pass.cpp
@@ -17,18 +17,10 @@
 #include <type_traits>
 
 typedef std::allocator<void> A1;
-typedef std::allocator<void const> A2;
-struct A3 : std::allocator<void> { };
-struct A4 : std::allocator<void const> { };
+struct A2 : std::allocator<void> { };
 
 static_assert(std::is_trivially_default_constructible<A1>::value, "");
 static_assert(std::is_trivial<A1>::value, "");
 
 static_assert(std::is_trivially_default_constructible<A2>::value, "");
 static_assert(std::is_trivial<A2>::value, "");
-
-static_assert(std::is_trivially_default_constructible<A3>::value, "");
-static_assert(std::is_trivial<A3>::value, "");
-
-static_assert(std::is_trivially_default_constructible<A4>::value, "");
-static_assert(std::is_trivial<A4>::value, "");

diff  --git a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
index 57d3132234f5c..50fe3822ff834 100644
--- a/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
+++ b/libcxx/test/std/concepts/concepts.lang/concept.default.init/default_initializable.compile.pass.cpp
@@ -202,9 +202,6 @@ void test()
     test_not_const<std::array<      volatile int, 1>>();
     test_false    <std::array<const volatile int, 1>>();
     test_true     <std::deque<               int>>();
-#ifdef _LIBCPP_VERSION
-    test_true     <std::deque<const          int>>();
-#endif // _LIBCPP_VERSION
     test_true     <std::forward_list<int>>();
     test_true     <std::list<int>>();
     test_true     <std::vector<int>>();
@@ -223,9 +220,6 @@ void test()
 
     // Container adaptors
     test_true     <std::stack<               int>>();
-#ifdef _LIBCPP_VERSION
-    test_true     <std::stack<const          int>>();
-#endif // _LIBCPP_VERSION
     test_true     <std::queue<int>>();
     test_true     <std::priority_queue<int>>();
 

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
index 6e6ff1f2d1344..a278bc41ef761 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.ctor.pass.cpp
@@ -37,12 +37,12 @@ TEST_CONSTEXPR_CXX20 bool test() {
 
 int main(int, char**) {
   test<char>();
-  test<char const>();
+  test<int>();
   test<void>();
 
 #if TEST_STD_VER > 17
   static_assert(test<char>());
-  static_assert(test<char const>());
+  static_assert(test<int>());
   static_assert(test<void>());
 #endif
   return 0;

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
index a095ca102491e..69c6595c98645 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.dtor.pass.cpp
@@ -26,15 +26,9 @@ int main(int, char**)
 {
     test<int>();
     test<void>();
-#ifdef _LIBCPP_VERSION // extension
-    test<int const>();
-#endif // _LIBCPP_VERSION
 
     static_assert(test<int>());
     static_assert(test<void>());
-#ifdef _LIBCPP_VERSION // extension
-    static_assert(test<int const>());
-#endif // _LIBCPP_VERSION
 
     return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
index f12b6808edeb3..13d2d65881ef6 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.constexpr.size.verify.cpp
@@ -35,6 +35,5 @@ constexpr bool test()
 int main(int, char**)
 {
     static_assert(test<double>()); // expected-error {{static_assert expression is not an integral constant expression}}
-    LIBCPP_STATIC_ASSERT(test<const double>()); // expected-error {{static_assert expression is not an integral constant expression}}
     return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
index 6b9b12c822424..56efcacf067f1 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -44,7 +44,6 @@ void test()
 int main(int, char**)
 {
     test<double>();
-    LIBCPP_ONLY(test<const double>());
 
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
index 901f04730ee8f..15c247a82b993 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.deprecated_in_cxx17.verify.cpp
@@ -35,13 +35,6 @@ int main(int, char**) {
         typedef std::allocator<char>::const_reference ConstReference;   // expected-warning {{'const_reference' is deprecated}}
         typedef std::allocator<char>::rebind<int>::other Rebind;        // expected-warning {{'rebind<int>' is deprecated}}
     }
-    {
-        typedef std::allocator<char const>::pointer Pointer;                  // expected-warning {{'pointer' is deprecated}}
-        typedef std::allocator<char const>::const_pointer ConstPointer;       // expected-warning {{'const_pointer' is deprecated}}
-        typedef std::allocator<char const>::reference Reference;              // expected-warning {{'reference' is deprecated}}
-        typedef std::allocator<char const>::const_reference ConstReference;   // expected-warning {{'const_reference' is deprecated}}
-        typedef std::allocator<char const>::rebind<int>::other Rebind;        // expected-warning {{'rebind<int>' is deprecated}}
-    }
     {
         typedef std::allocator<void>::pointer Pointer;                  // expected-warning {{'pointer' is deprecated}}
         typedef std::allocator<void>::const_pointer ConstPointer;       // expected-warning {{'const_pointer' is deprecated}}

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
index 74adc6943594d..5761c28da09df 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
@@ -59,8 +59,5 @@ void test() {
 
 int main(int, char**) {
     test<char>();
-#ifdef _LIBCPP_VERSION
-    test<char const>(); // extension
-#endif
     return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
index 1d91a022867da..47cdf399ee477 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator_types.removed_in_cxx20.verify.cpp
@@ -31,17 +31,16 @@
 template <typename T>
 void check()
 {
-    typedef typename std::allocator<T>::pointer AP;                      // expected-error 3 {{no type named 'pointer'}}
-    typedef typename std::allocator<T>::const_pointer ACP;               // expected-error 3 {{no type named 'const_pointer'}}
-    typedef typename std::allocator<T>::reference AR;                    // expected-error 3 {{no type named 'reference'}}
-    typedef typename std::allocator<T>::const_reference ACR;             // expected-error 3 {{no type named 'const_reference'}}
-    typedef typename std::allocator<T>::template rebind<int>::other ARO; // expected-error 3 {{no member named 'rebind'}}
+    typedef typename std::allocator<T>::pointer AP;                      // expected-error 2 {{no type named 'pointer'}}
+    typedef typename std::allocator<T>::const_pointer ACP;               // expected-error 2 {{no type named 'const_pointer'}}
+    typedef typename std::allocator<T>::reference AR;                    // expected-error 2 {{no type named 'reference'}}
+    typedef typename std::allocator<T>::const_reference ACR;             // expected-error 2 {{no type named 'const_reference'}}
+    typedef typename std::allocator<T>::template rebind<int>::other ARO; // expected-error 2 {{no member named 'rebind'}}
 }
 
 int main(int, char**)
 {
     check<char>();
-    check<char const>();
     check<void>();
     return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp b/libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp
index e7fd797966710..028eebbb974a6 100644
--- a/libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp
+++ b/libcxx/test/std/utilities/memory/specialized.algorithms/specialized.construct/construct_at.pass.cpp
@@ -82,7 +82,7 @@ constexpr bool test()
     }
 
     {
-        std::allocator<Counted const> a;
+        std::allocator<Counted> a;
         Counted const* p = a.allocate(2);
         int count = 0;
         std::construct_at(p, count);
@@ -93,7 +93,7 @@ constexpr bool test()
         assert(count == 1);
         p->~Counted();
         assert(count == 0);
-        a.deallocate(p, 2);
+        a.deallocate(const_cast<Counted*>(p), 2);
     }
 
     return true;

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
index 117503c18abed..6f641cec24bf4 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
@@ -46,19 +46,34 @@ int A::count = 0;
 
 int main(int, char**)
 {
-  globalMemCounter.reset();
-  {
-    std::auto_ptr<A> ptr(new A);
-    A* raw_ptr = ptr.get();
-    std::shared_ptr<B> p(std::move(ptr));
-    assert(A::count == 1);
-    assert(B::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == raw_ptr);
-    assert(ptr.get() == 0);
-  }
+    globalMemCounter.reset();
+    {
+        std::auto_ptr<A> ptr(new A);
+        A* raw_ptr = ptr.get();
+        std::shared_ptr<B> p(std::move(ptr));
+        assert(A::count == 1);
+        assert(B::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == raw_ptr);
+        assert(ptr.get() == 0);
+    }
+    assert(A::count == 0);
+    assert(globalMemCounter.checkOutstandingNewEq(0));
+
+    globalMemCounter.reset();
+    {
+        std::auto_ptr<A const> ptr(new A);
+        A const* raw_ptr = ptr.get();
+        std::shared_ptr<B const> p(std::move(ptr));
+        assert(A::count == 1);
+        assert(B::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == raw_ptr);
+        assert(ptr.get() == 0);
+    }
     assert(A::count == 0);
     assert(globalMemCounter.checkOutstandingNewEq(0));
+
 #if !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT)
     {
         std::auto_ptr<A> ptr(new A);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
index 05810e80e914a..7373adf6eaa02 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/deduction.pass.cpp
@@ -22,7 +22,7 @@
 struct A {};
 
 struct D {
-  void operator()(A* ptr) const
+  void operator()(A const* ptr) const
   {
     delete ptr;
   }
@@ -39,22 +39,49 @@ int main(int, char**)
     assert(s.use_count() == 2);
     assert(s0.get() == s.get());
   }
+  {
+    std::shared_ptr<A const> s0(new A);
+    std::weak_ptr<A const> w = s0;
+    auto s = std::shared_ptr(w);
+    ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A const>);
+    assert(s0.use_count() == 2);
+    assert(s.use_count() == 2);
+    assert(s0.get() == s.get());
+  }
+
   {
     std::unique_ptr<A> u(new A);
-    A* const uPointee = u.get();
+    A* uPointee = u.get();
     std::shared_ptr s = std::move(u);
     ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A>);
     assert(u == nullptr);
     assert(s.get() == uPointee);
   }
+  {
+    std::unique_ptr<A const> u(new A);
+    A const* uPointee = u.get();
+    std::shared_ptr s = std::move(u);
+    ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A const>);
+    assert(u == nullptr);
+    assert(s.get() == uPointee);
+  }
+
   {
     std::unique_ptr<A, D> u(new A, D{});
-    A* const uPointee = u.get();
+    A* uPointee = u.get();
     std::shared_ptr s(std::move(u));
     ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A>);
     assert(u == nullptr);
     assert(s.get() == uPointee);
   }
+  {
+    std::unique_ptr<A const, D> u(new A, D{});
+    A const* uPointee = u.get();
+    std::shared_ptr s(std::move(u));
+    ASSERT_SAME_TYPE(decltype(s), std::shared_ptr<A const>);
+    assert(u == nullptr);
+    assert(s.get() == uPointee);
+  }
 
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
index 4efa18f63f523..6ac7ad6447619 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp
@@ -26,8 +26,11 @@ void test() {
 
 int main(int, char**) {
   test<int>();
+  test<int const>();
   test<A>();
+  test<A const>();
   test<int*>();
+  test<int const*>();
   test<int[]>();
   test<int[8]>();
 

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
index c9a46dc48f531..f307c9e9f239d 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp
@@ -17,9 +17,17 @@
 
 int main(int, char**)
 {
+  {
     std::shared_ptr<int> p(nullptr);
     assert(p.use_count() == 0);
     assert(p.get() == 0);
+  }
+
+  {
+    std::shared_ptr<int const> p(nullptr);
+    assert(p.use_count() == 0);
+    assert(p.get() == 0);
+  }
 
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
index b84e1659caadb..49497b6956b9f 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp
@@ -31,21 +31,26 @@ int A::count = 0;
 int main(int, char**)
 {
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
 
-  return 0;
+    {
+        std::shared_ptr<A const> p(nullptr, test_deleter<A const>(3));
+        assert(p.get() == nullptr);
+    }
+
+    return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
index 4d59d7f5667f8..4e9fc227b99e8 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp
@@ -32,19 +32,19 @@ int main(int, char**)
 {
     test_allocator_statistics alloc_stats;
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
-    assert(alloc_stats.count == 1);
-    assert(alloc_stats.alloc_count == 1);
+        assert(alloc_stats.count == 1);
+        assert(alloc_stats.alloc_count == 1);
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
@@ -52,37 +52,39 @@ int main(int, char**)
     assert(alloc_stats.count == 0);
     assert(alloc_stats.alloc_count == 0);
     test_deleter<A>::dealloc_count = 0;
+
     // Test an allocator with a minimal interface
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(1), bare_allocator<void>());
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count ==1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(1), bare_allocator<void>());
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count ==1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 1);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 1);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
     test_deleter<A>::dealloc_count = 0;
+
 #if TEST_STD_VER >= 11
     // Test an allocator that returns class-type pointers
     {
-    std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>());
-    assert(A::count == 0);
-    assert(p.use_count() == 1);
-    assert(p.get() == 0);
-    assert(test_deleter<A>::count ==1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        std::shared_ptr<A> p(nullptr, test_deleter<A>(1), min_allocator<void>());
+        assert(A::count == 0);
+        assert(p.use_count() == 1);
+        assert(p.get() == 0);
+        assert(test_deleter<A>::count ==1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 1);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 1);
 #endif
     }
     assert(A::count == 0);
@@ -90,5 +92,11 @@ int main(int, char**)
     assert(test_deleter<A>::dealloc_count == 1);
 #endif
 
+    // Make sure we can use this constructor with a pointer-to-const
+    {
+        std::shared_ptr<A const> p(nullptr, test_deleter<A const>(3), test_allocator<A>(5, &alloc_stats));
+        (void)p;
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
index c88bdd1c6e561..ef3270efc8253 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp
@@ -29,43 +29,53 @@ int A::count = 0;
 int main(int, char**)
 {
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr);
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
+        assert(A::count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr);
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
     }
-    assert(A::count == 0);
+
+    {
+        assert(A::count == 0);
+        A const* ptr = new A;
+        std::shared_ptr<A const> p(ptr);
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+    }
+
     {
-    A* ptr = new A;
-    std::shared_ptr<void> p(ptr);
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
+        assert(A::count == 0);
+        A* ptr = new A;
+        std::shared_ptr<void> p(ptr);
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
     }
-    assert(A::count == 0);
 
 #if TEST_STD_VER > 14
     {
-      std::shared_ptr<A[8]> pA(new A[8]);
-      assert(pA.use_count() == 1);
-      assert(A::count == 8);
+        assert(A::count == 0);
+        std::shared_ptr<A[8]> pA(new A[8]);
+        assert(pA.use_count() == 1);
+        assert(A::count == 8);
     }
-    assert(A::count == 0);
 
     {
-      std::shared_ptr<A[]> pA(new A[8]);
-      assert(pA.use_count() == 1);
-      assert(A::count == 8);
+        assert(A::count == 0);
+        std::shared_ptr<A[]> pA(new A[8]);
+        assert(pA.use_count() == 1);
+        assert(A::count == 8);
     }
-    assert(A::count == 0);
 
     {
-      std::shared_ptr<const A[]> pA(new A[8]);
-      assert(pA.use_count() == 1);
-      assert(A::count == 8);
+          assert(A::count == 0);
+        std::shared_ptr<const A[]> pA(new A[8]);
+        assert(pA.use_count() == 1);
+        assert(A::count == 8);
     }
-    assert(A::count == 0);
 #endif
 
     return 0;

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
index e5abbebb962bb..b3580e25fe52c 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp
@@ -63,23 +63,29 @@ class MoveDeleter
 int main(int, char**)
 {
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3));
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr, test_deleter<A>(3));
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
 
+    {
+        A const* ptr = new A;
+        std::shared_ptr<A const> p(ptr, test_deleter<A const>(3));
+        assert(p.get() == ptr);
+    }
+
     {
         // Make sure we can't construct with:
         //    a) a deleter that doesn't have an operator ()(int*)

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
index 3b86b07d79234..2fc25282230c8 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp
@@ -62,62 +62,92 @@ class MoveDeleter
 
 int main(int, char**)
 {
-    test_allocator_statistics alloc_stats;
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        test_allocator_statistics alloc_stats;
+        {
+            A* ptr = new A;
+            std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5, &alloc_stats));
+            assert(A::count == 1);
+            assert(p.use_count() == 1);
+            assert(p.get() == ptr);
+            assert(test_deleter<A>::count == 1);
+            assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+            test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+            assert(d);
+            assert(d->state() == 3);
 #endif
-    assert(alloc_stats.count == 1);
-    assert(alloc_stats.alloc_count == 1);
+            assert(alloc_stats.count == 1);
+            assert(alloc_stats.alloc_count == 1);
+        }
+        assert(A::count == 0);
+        assert(test_deleter<A>::count == 0);
+        assert(test_deleter<A>::dealloc_count == 1);
+        assert(alloc_stats.count == 0);
+        assert(alloc_stats.alloc_count == 0);
+        test_deleter<A>::dealloc_count = 0;
     }
-    assert(A::count == 0);
-    assert(test_deleter<A>::count == 0);
-    assert(test_deleter<A>::dealloc_count == 1);
-    assert(alloc_stats.count == 0);
-    assert(alloc_stats.alloc_count == 0);
-    test_deleter<A>::dealloc_count = 0;
+
+    {
+        test_allocator_statistics alloc_stats;
+        {
+            A const* ptr = new A;
+            std::shared_ptr<A const> p(ptr, test_deleter<A const>(3), test_allocator<A>(5, &alloc_stats));
+            assert(A::count == 1);
+            assert(p.use_count() == 1);
+            assert(p.get() == ptr);
+            assert(test_deleter<A const>::count == 1);
+            assert(test_deleter<A const>::dealloc_count == 0);
+#ifndef TEST_HAS_NO_RTTI
+            test_deleter<A const>* d = std::get_deleter<test_deleter<A const> >(p);
+            assert(d);
+            assert(d->state() == 3);
+#endif
+            assert(alloc_stats.count == 1);
+            assert(alloc_stats.alloc_count == 1);
+        }
+        assert(A::count == 0);
+        assert(test_deleter<A const>::count == 0);
+        assert(test_deleter<A const>::dealloc_count == 1);
+        assert(alloc_stats.count == 0);
+        assert(alloc_stats.alloc_count == 0);
+        test_deleter<A const>::dealloc_count = 0;
+    }
+
     // Test an allocator with a minimal interface
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3), bare_allocator<void>());
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr, test_deleter<A>(3), bare_allocator<void>());
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);
     assert(test_deleter<A>::count == 0);
     assert(test_deleter<A>::dealloc_count == 1);
     test_deleter<A>::dealloc_count = 0;
+
 #if TEST_STD_VER >= 11
     // Test an allocator that returns class-type pointers
     {
-    A* ptr = new A;
-    std::shared_ptr<A> p(ptr, test_deleter<A>(3), min_allocator<void>());
-    assert(A::count == 1);
-    assert(p.use_count() == 1);
-    assert(p.get() == ptr);
-    assert(test_deleter<A>::count == 1);
-    assert(test_deleter<A>::dealloc_count == 0);
+        A* ptr = new A;
+        std::shared_ptr<A> p(ptr, test_deleter<A>(3), min_allocator<void>());
+        assert(A::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == ptr);
+        assert(test_deleter<A>::count == 1);
+        assert(test_deleter<A>::dealloc_count == 0);
 #ifndef TEST_HAS_NO_RTTI
-    test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
-    assert(d);
-    assert(d->state() == 3);
+        test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
+        assert(d);
+        assert(d->state() == 3);
 #endif
     }
     assert(A::count == 0);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
index c9bd0f0331158..fcb6ae71b4839 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp
@@ -61,5 +61,11 @@ int main(int, char**)
     }
     assert(A::count == 0);
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        std::shared_ptr<A const> pA2(pA);
+        assert(pA.get() == pA2.get());
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
index 20cfd52d6901d..26f381c9a2892 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp
@@ -152,5 +152,11 @@ int main(int, char**)
     assert(A::count == 0);
 #endif
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        std::shared_ptr<B const> pB(pA);
+        assert(pB.get() == pA.get());
+    }
+
     return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
index 167baf87825db..84ec26eb140ee 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp
@@ -129,5 +129,12 @@ int main(int, char**)
     assert(A::count == 0);
 #endif
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        B const* p = pA.get();
+        std::shared_ptr<B const> pB(std::move(pA));
+        assert(pB.get() == p);
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
index 580ab3d35f1b3..9ef8ed7876f67 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
@@ -61,6 +61,26 @@ int main(int, char**)
     assert(A::count == 0);
     assert(B::count == 0);
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        assert(pA.use_count() == 1);
+
+        {
+            B const b;
+            std::shared_ptr<B const> pB(pA, &b);
+            assert(A::count == 1);
+            assert(B::count == 1);
+            assert(pA.use_count() == 2);
+            assert(pB.use_count() == 2);
+            assert(pB.get() == &b);
+        }
+        assert(pA.use_count() == 1);
+        assert(A::count == 1);
+        assert(B::count == 0);
+    }
+    assert(A::count == 0);
+    assert(B::count == 0);
+
     int *pi = new int;
     {
       std::shared_ptr<int> p1(nullptr);

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
index bc000949c6857..8637e3fc8cf29 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp
@@ -57,6 +57,7 @@ int main(int, char**)
         assert(A::count == 1);
 #endif
     }
+
     assert(A::count == 0);
     {
         std::shared_ptr<A> pA;
@@ -74,5 +75,12 @@ int main(int, char**)
     }
     assert(A::count == 0);
 
+    {
+        std::shared_ptr<A const> pA(new A);
+        A const* p = pA.get();
+        std::shared_ptr<A const> pA2(std::move(pA));
+        assert(pA2.get() == p);
+    }
+
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
index ef0b9102c6cda..a86bff84435f9 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
@@ -94,6 +94,18 @@ int main(int, char**)
         assert(p.get() == raw_ptr);
         assert(ptr.get() == 0);
     }
+
+    {
+        std::unique_ptr<A const> ptr(new A);
+        A const* raw_ptr = ptr.get();
+        std::shared_ptr<B const> p(std::move(ptr));
+        assert(A::count == 1);
+        assert(B::count == 1);
+        assert(p.use_count() == 1);
+        assert(p.get() == raw_ptr);
+        assert(ptr.get() == 0);
+    }
+
 #ifndef TEST_HAS_NO_EXCEPTIONS
     assert(A::count == 0);
     {

diff  --git a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
index 30fa6ccd1806a..57d7cc58ef68c 100644
--- a/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
+++ b/libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
@@ -65,6 +65,15 @@ int main(int, char**)
         assert(A::count == 1);
     }
     assert(A::count == 0);
+    {
+        std::shared_ptr<A const> sp0(new A);
+        std::weak_ptr<A const> wp(sp0);
+        std::shared_ptr<A const> sp(wp);
+        assert(sp.use_count() == 2);
+        assert(sp.get() == sp0.get());
+        assert(A::count == 1);
+    }
+    assert(A::count == 0);
 #ifndef TEST_HAS_NO_EXCEPTIONS
     {
         std::shared_ptr<A> sp0(new A);


        


More information about the libcxx-commits mailing list