mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Obey __cpp_sized_deallocation and __cpp_aligned_new
Don't assume that just because the language version is C++17 that the standard library offers all C++17 features, too. When using clang-6.0 and --std=c++17 on Ubuntu 18.04 with libstdc++, __cpp_sized_deallocation is false.
This commit is contained in:
parent
6c29cbf88d
commit
759221f5c5
@ -574,10 +574,10 @@ public:
|
|||||||
if (type->operator_new) {
|
if (type->operator_new) {
|
||||||
vptr = type->operator_new(type->type_size);
|
vptr = type->operator_new(type->type_size);
|
||||||
} else {
|
} else {
|
||||||
#if defined(PYBIND11_CPP17)
|
#ifdef __cpp_aligned_new
|
||||||
if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
|
if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
|
||||||
vptr = ::operator new(type->type_size,
|
vptr = ::operator new(type->type_size,
|
||||||
(std::align_val_t) type->type_align);
|
std::align_val_t(type->type_align));
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
vptr = ::operator new(type->type_size);
|
vptr = ::operator new(type->type_size);
|
||||||
|
@ -1003,14 +1003,21 @@ void call_operator_delete(T *p, size_t s, size_t) { T::operator delete(p, s); }
|
|||||||
|
|
||||||
inline void call_operator_delete(void *p, size_t s, size_t a) {
|
inline void call_operator_delete(void *p, size_t s, size_t a) {
|
||||||
(void)s; (void)a;
|
(void)s; (void)a;
|
||||||
#if defined(PYBIND11_CPP17)
|
#ifdef __cpp_aligned_new
|
||||||
if (a > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
|
if (a > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
|
||||||
::operator delete(p, s, std::align_val_t(a));
|
#ifdef __cpp_sized_deallocation
|
||||||
else
|
::operator delete(p, s, std::align_val_t(a));
|
||||||
|
#else
|
||||||
|
::operator delete(p, std::align_val_t(a));
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef __cpp_sized_deallocation
|
||||||
::operator delete(p, s);
|
::operator delete(p, s);
|
||||||
#else
|
#else
|
||||||
::operator delete(p);
|
::operator delete(p);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
NAMESPACE_END(detail)
|
NAMESPACE_END(detail)
|
||||||
|
Loading…
Reference in New Issue
Block a user