[libcxx] r305397 - In several places in std::allocator<const T> (and one in shared_ptr, we were casting a 'const T*' to a 'void *' - implicitly casting away the const. Add const_cast to make that explicit. No functional change.

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 14 09:54:44 PDT 2017


Author: marshall
Date: Wed Jun 14 11:54:43 2017
New Revision: 305397

URL: http://llvm.org/viewvc/llvm-project?rev=305397&view=rev
Log:
In several places in std::allocator<const T> (and one in shared_ptr, we were casting a 'const T*' to a 'void *' - implicitly casting away the const. Add const_cast to make that explicit. No functional change.

Modified:
    libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=305397&r1=305396&r2=305397&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Jun 14 11:54:43 2017
@@ -1884,7 +1884,7 @@ public:
         return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
     }
     _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
-        {_VSTD::__libcpp_deallocate((void*)__p);}
+        {_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));}
     _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
         {return size_type(~0) / sizeof(_Tp);}
 #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
@@ -1900,7 +1900,7 @@ public:
         void
         construct(pointer __p)
         {
-            ::new((void*)__p) _Tp();
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp();
         }
 # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
 
@@ -1909,14 +1909,14 @@ public:
         void
         construct(pointer __p, _A0& __a0)
         {
-            ::new((void*)__p) _Tp(__a0);
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
         }
     template <class _A0>
         _LIBCPP_INLINE_VISIBILITY
         void
         construct(pointer __p, const _A0& __a0)
         {
-            ::new((void*)__p) _Tp(__a0);
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
         }
 # endif  // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
     template <class _A0, class _A1>
@@ -1924,28 +1924,28 @@ public:
         void
         construct(pointer __p, _A0& __a0, _A1& __a1)
         {
-            ::new((void*)__p) _Tp(__a0, __a1);
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
         }
     template <class _A0, class _A1>
         _LIBCPP_INLINE_VISIBILITY
         void
         construct(pointer __p, const _A0& __a0, _A1& __a1)
         {
-            ::new((void*)__p) _Tp(__a0, __a1);
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
         }
     template <class _A0, class _A1>
         _LIBCPP_INLINE_VISIBILITY
         void
         construct(pointer __p, _A0& __a0, const _A1& __a1)
         {
-            ::new((void*)__p) _Tp(__a0, __a1);
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
         }
     template <class _A0, class _A1>
         _LIBCPP_INLINE_VISIBILITY
         void
         construct(pointer __p, const _A0& __a0, const _A1& __a1)
         {
-            ::new((void*)__p) _Tp(__a0, __a1);
+            ::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
         }
 #endif  // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
     _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
@@ -3890,7 +3890,9 @@ public:
     template <class _Dp>
         _LIBCPP_INLINE_VISIBILITY
         _Dp* __get_deleter() const _NOEXCEPT
-            {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
+            {return static_cast<_Dp*>(__cntrl_
+                    ? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp))) 
+                      : nullptr);}
 #endif  // _LIBCPP_NO_RTTI
 
 #ifndef _LIBCPP_HAS_NO_VARIADICS




More information about the cfe-commits mailing list