@@ -896,6 +896,7 @@ class generic_type : public object {
896896 tinfo->type = (PyTypeObject *) m_ptr;
897897 tinfo->cpptype = rec.type ;
898898 tinfo->type_size = rec.type_size ;
899+ tinfo->type_align = rec.type_align ;
899900 tinfo->operator_new = rec.operator_new ;
900901 tinfo->holder_size_in_ptrs = size_in_ptrs (rec.holder_size );
901902 tinfo->init_instance = rec.init_instance ;
@@ -987,11 +988,21 @@ template <typename T> struct has_operator_delete_size<T, void_t<decltype(static_
987988 : std::true_type { };
988989// / Call class-specific delete if it exists or global otherwise. Can also be an overload set.
989990template <typename T, enable_if_t <has_operator_delete<T>::value, int > = 0 >
990- void call_operator_delete (T *p, size_t ) { T::operator delete (p); }
991+ void call_operator_delete (T *p, size_t , size_t ) { T::operator delete (p); }
991992template <typename T, enable_if_t <!has_operator_delete<T>::value && has_operator_delete_size<T>::value, int > = 0 >
992- void call_operator_delete (T *p, size_t s) { T::operator delete (p, s); }
993+ void call_operator_delete (T *p, size_t s, size_t ) { T::operator delete (p, s); }
993994
994- inline void call_operator_delete (void *p, size_t ) { ::operator delete (p); }
995+ inline void call_operator_delete (void *p, size_t s, size_t a) {
996+ (void )s; (void )a;
997+ #if defined(PYBIND11_CPP17)
998+ if (a > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
999+ ::operator delete (p, s, std::align_val_t (a));
1000+ else
1001+ ::operator delete (p, s);
1002+ #else
1003+ ::operator delete (p);
1004+ #endif
1005+ }
9951006
9961007NAMESPACE_END (detail)
9971008
@@ -1054,6 +1065,7 @@ class class_ : public detail::generic_type {
10541065 record.name = name;
10551066 record.type = &typeid (type);
10561067 record.type_size = sizeof (conditional_t <has_alias, type_alias, type>);
1068+ record.type_align = alignof (conditional_t <has_alias, type_alias, type>&);
10571069 record.holder_size = sizeof (holder_type);
10581070 record.init_instance = init_instance;
10591071 record.dealloc = dealloc;
@@ -1329,7 +1341,10 @@ class class_ : public detail::generic_type {
13291341 v_h.set_holder_constructed (false );
13301342 }
13311343 else {
1332- detail::call_operator_delete (v_h.value_ptr <type>(), v_h.type ->type_size );
1344+ detail::call_operator_delete (v_h.value_ptr <type>(),
1345+ v_h.type ->type_size ,
1346+ v_h.type ->type_align
1347+ );
13331348 }
13341349 v_h.value_ptr () = nullptr ;
13351350 }
0 commit comments