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.
This commit is contained in:
Wenzel Jakob
2018-11-09 20:14:53 +01:00
committed by GitHub
parent adc2cdd5c4
commit e2eca4f8f8
6 changed files with 55 additions and 8 deletions

View File

@@ -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 @@ TEST_SUBMODULE(class_, m) {
[](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; };