[libcxx] r180213 - default_delete needs a static_assert against void types. I had previously thought that sizeof(void) would take care of this. I was wrong.

Howard Hinnant hhinnant at apple.com
Wed Apr 24 12:44:26 PDT 2013


Author: hhinnant
Date: Wed Apr 24 14:44:26 2013
New Revision: 180213

URL: http://llvm.org/viewvc/llvm-project?rev=180213&view=rev
Log:
default_delete needs a static_assert against void types.  I had previously thought that sizeof(void) would take care of this.  I was wrong.

Added:
    libcxx/trunk/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp
Modified:
    libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=180213&r1=180212&r2=180213&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Apr 24 14:44:26 2013
@@ -2485,6 +2485,7 @@ struct _LIBCPP_TYPE_VIS default_delete
     _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;
         }
 };
@@ -2507,6 +2508,7 @@ public:
                          typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) 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;
         }
 };

Added: libcxx/trunk/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp?rev=180213&view=auto
==============================================================================
--- libcxx/trunk/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp (added)
+++ libcxx/trunk/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp Wed Apr 24 14:44:26 2013
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// default_delete
+
+// Test that default_delete's operator() requires a complete type
+
+#include <memory>
+#include <cassert>
+
+int main()
+{
+    std::default_delete<const void> d;
+    const void* p = 0;
+    d(p);
+}





More information about the cfe-commits mailing list