[PATCH] D21320: Alternative to D1332

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 21:00:34 PDT 2016


mclow.lists created this revision.
mclow.lists added reviewers: EricWF, STL_MSFT.
mclow.lists added a subscriber: cfe-commits.

There's a bug in the standard, where the default deleter will always call `delete x`; even if `x` is an array type.  This shows up for `shared_ptr<T[]>`.

Do the right thing, and delete the array when you have one.


http://reviews.llvm.org/D21320

Files:
  include/memory

Index: include/memory
===================================================================
--- include/memory
+++ include/memory
@@ -2533,11 +2533,16 @@
     template <class _Up>
         _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
              typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
-    _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
+
+    _LIBCPP_INLINE_VISIBILITY void
+    operator() (_Tp* __ptr) const _NOEXCEPT
         {
             static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
             static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
-            delete __ptr;
+            if ( is_array<_Tp>::value )
+                delete [] __ptr;
+            else
+                delete __ptr;
         }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21320.60650.patch
Type: text/x-patch
Size: 880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160614/ad386b28/attachment.bin>


More information about the cfe-commits mailing list