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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@180213 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant 2013-04-24 19:44:26 +00:00
parent c5e6aa5f5c
commit 05e7d24b3d
2 changed files with 26 additions and 0 deletions

View File

@ -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;
}
};

View File

@ -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);
}