diff options
author | Bobby R. Bruce <bbruce@ucdavis.edu> | 2019-09-23 13:52:58 -0700 |
---|---|---|
committer | Bobby R. Bruce <bbruce@ucdavis.edu> | 2019-09-24 21:40:15 +0000 |
commit | f97cf54db7a6f7642cc9fd122f23c4396c39bcf0 (patch) | |
tree | 17d2ed22a1114cb138500d46afddb3bafcc2b418 /ext/pybind11/tests/test_class.cpp | |
parent | 9235ae56c282d5a02ada3ed9b4e0fe2ee5738bde (diff) | |
download | gem5-f97cf54db7a6f7642cc9fd122f23c4396c39bcf0.tar.xz |
ext: Updated Pybind11 to version 2.4.1.
This updates Pybind11 from version 2.2.1 to version 2.4.1. This fixes
warning/error received when "<experiment/optional>" is used when
compiling using c++14 with clang. It should be noted that
"ext/pybind11/include/pybind11/std.h" has been changed to include a fix
added by commit ba42457254cc362eddc099f22b60d469cc6369e0. This is
necessary to avoid build errors.
Built: Linux (gcc, c++11) and MacOS (clang, c++14).
Tested: Ran quick tests for X86, ARM, and RISC-V.
Deprecates: https://gem5-review.googlesource.com/c/public/gem5/+/21019
Change-Id: Ie9783511cb6be50136076a55330e645f4f36d075
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21119
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'ext/pybind11/tests/test_class.cpp')
-rw-r--r-- | ext/pybind11/tests/test_class.cpp | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/ext/pybind11/tests/test_class.cpp b/ext/pybind11/tests/test_class.cpp index 222190617..499d0cc51 100644 --- a/ext/pybind11/tests/test_class.cpp +++ b/ext/pybind11/tests/test_class.cpp @@ -10,10 +10,27 @@ #include "pybind11_tests.h" #include "constructor_stats.h" #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)} {} + template <typename T> + NoBraceInitialization(std::initializer_list<T> l) : vec(l) {} + + std::vector<int> vec; +}; TEST_SUBMODULE(class_, m) { // test_instance struct NoConstructor { + NoConstructor() = default; + NoConstructor(const NoConstructor &) = default; + NoConstructor(NoConstructor &&) = default; static NoConstructor *new_instance() { auto *ptr = new NoConstructor(); print_created(ptr, "via new_instance"); @@ -82,7 +99,12 @@ TEST_SUBMODULE(class_, m) { m.def("dog_bark", [](const Dog &dog) { return dog.bark(); }); // test_automatic_upcasting - struct BaseClass { virtual ~BaseClass() {} }; + struct BaseClass { + BaseClass() = default; + BaseClass(const BaseClass &) = default; + BaseClass(BaseClass &&) = default; + virtual ~BaseClass() {} + }; struct DerivedClass1 : BaseClass { }; struct DerivedClass2 : BaseClass { }; @@ -291,6 +313,12 @@ TEST_SUBMODULE(class_, m) { .def(py::init<int, const std::string &>()) .def_readwrite("field1", &BraceInitialization::field1) .def_readwrite("field2", &BraceInitialization::field2); + // We *don't* want to construct using braces when the given constructor argument maps to a + // constructor, because brace initialization could go to the wrong place (in particular when + // there is also an `initializer_list<T>`-accept constructor): + py::class_<NoBraceInitialization>(m, "NoBraceInitialization") + .def(py::init<std::vector<int>>()) + .def_readonly("vec", &NoBraceInitialization::vec); // test_reentrant_implicit_conversion_failure // #1035: issue with runaway reentrant implicit conversion @@ -302,6 +330,43 @@ TEST_SUBMODULE(class_, m) { .def(py::init<const BogusImplicitConversion &>()); py::implicitly_convertible<int, BogusImplicitConversion>(); + + // test_qualname + // #1166: nested class docstring doesn't show nested name + // Also related: tests that __qualname__ is set properly + struct NestBase {}; + struct Nested {}; + py::class_<NestBase> base(m, "NestBase"); + base.def(py::init<>()); + py::class_<Nested>(base, "Nested") + .def(py::init<>()) + .def("fn", [](Nested &, int, NestBase &, Nested &) {}) + .def("fa", [](Nested &, int, NestBase &, Nested &) {}, + "a"_a, "b"_a, "c"_a); + base.def("g", [](NestBase &, Nested &) {}); + base.def("h", []() { return NestBase(); }); + + // test_error_after_conversion + // The second-pass path through dispatcher() previously didn't + // remember which overload was used, and would crash trying to + // generate a useful error message + + struct NotRegistered {}; + struct StringWrapper { std::string str; }; + m.def("test_error_after_conversions", [](int) {}); + m.def("test_error_after_conversions", + [](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; }; |