Support C++17 aligned new statement (#1582)
* Support C++17 aligned new statement
This patch makes pybind11 aware of nonstandard alignment requirements in
bound types and passes on this information to C++17 aligned 'new'
operator. Pre-C++17, the behavior is unchanged.
diff --git a/tests/test_class.cpp b/tests/test_class.cpp
index 9ed1f50..499d0cc 100644
--- a/tests/test_class.cpp
+++ b/tests/test_class.cpp
@@ -12,6 +12,10 @@
#include "local_bindings.h"
#include <pybind11/stl.h>
+#if defined(_MSC_VER)
+# pragma warning(disable: 4324) // warning C4324: structure was padded due to alignment specifier
+#endif
+
// test_brace_initialization
struct NoBraceInitialization {
NoBraceInitialization(std::vector<int> v) : vec{std::move(v)} {}
@@ -354,6 +358,15 @@
[](StringWrapper) -> NotRegistered { return {}; });
py::class_<StringWrapper>(m, "StringWrapper").def(py::init<std::string>());
py::implicitly_convertible<std::string, StringWrapper>();
+
+ #if defined(PYBIND11_CPP17)
+ struct alignas(1024) Aligned {
+ std::uintptr_t ptr() const { return (uintptr_t) this; }
+ };
+ py::class_<Aligned>(m, "Aligned")
+ .def(py::init<>())
+ .def("ptr", &Aligned::ptr);
+ #endif
}
template <int N> class BreaksBase { public: virtual ~BreaksBase() = default; };