test_class.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /*
  2. tests/test_class.cpp -- test py::class_ definitions and basic functionality
  3. Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #if defined(__INTEL_COMPILER) && __cplusplus >= 201703L
  8. // Intel compiler requires a separate header file to support aligned new operators
  9. // and does not set the __cpp_aligned_new feature macro.
  10. // This header needs to be included before pybind11.
  11. #include <aligned_new>
  12. #endif
  13. #include "pybind11_tests.h"
  14. #include "constructor_stats.h"
  15. #include "local_bindings.h"
  16. #include <pybind11/stl.h>
  17. #if defined(_MSC_VER)
  18. # pragma warning(disable: 4324) // warning C4324: structure was padded due to alignment specifier
  19. #endif
  20. // test_brace_initialization
  21. struct NoBraceInitialization {
  22. NoBraceInitialization(std::vector<int> v) : vec{std::move(v)} {}
  23. template <typename T>
  24. NoBraceInitialization(std::initializer_list<T> l) : vec(l) {}
  25. std::vector<int> vec;
  26. };
  27. TEST_SUBMODULE(class_, m) {
  28. // test_instance
  29. struct NoConstructor {
  30. NoConstructor() = default;
  31. NoConstructor(const NoConstructor &) = default;
  32. NoConstructor(NoConstructor &&) = default;
  33. static NoConstructor *new_instance() {
  34. auto *ptr = new NoConstructor();
  35. print_created(ptr, "via new_instance");
  36. return ptr;
  37. }
  38. ~NoConstructor() { print_destroyed(this); }
  39. };
  40. py::class_<NoConstructor>(m, "NoConstructor")
  41. .def_static("new_instance", &NoConstructor::new_instance, "Return an instance");
  42. // test_inheritance
  43. class Pet {
  44. public:
  45. Pet(const std::string &name, const std::string &species)
  46. : m_name(name), m_species(species) {}
  47. std::string name() const { return m_name; }
  48. std::string species() const { return m_species; }
  49. private:
  50. std::string m_name;
  51. std::string m_species;
  52. };
  53. class Dog : public Pet {
  54. public:
  55. Dog(const std::string &name) : Pet(name, "dog") {}
  56. std::string bark() const { return "Woof!"; }
  57. };
  58. class Rabbit : public Pet {
  59. public:
  60. Rabbit(const std::string &name) : Pet(name, "parrot") {}
  61. };
  62. class Hamster : public Pet {
  63. public:
  64. Hamster(const std::string &name) : Pet(name, "rodent") {}
  65. };
  66. class Chimera : public Pet {
  67. Chimera() : Pet("Kimmy", "chimera") {}
  68. };
  69. py::class_<Pet> pet_class(m, "Pet");
  70. pet_class
  71. .def(py::init<std::string, std::string>())
  72. .def("name", &Pet::name)
  73. .def("species", &Pet::species);
  74. /* One way of declaring a subclass relationship: reference parent's class_ object */
  75. py::class_<Dog>(m, "Dog", pet_class)
  76. .def(py::init<std::string>());
  77. /* Another way of declaring a subclass relationship: reference parent's C++ type */
  78. py::class_<Rabbit, Pet>(m, "Rabbit")
  79. .def(py::init<std::string>());
  80. /* And another: list parent in class template arguments */
  81. py::class_<Hamster, Pet>(m, "Hamster")
  82. .def(py::init<std::string>());
  83. /* Constructors are not inherited by default */
  84. py::class_<Chimera, Pet>(m, "Chimera");
  85. m.def("pet_name_species", [](const Pet &pet) { return pet.name() + " is a " + pet.species(); });
  86. m.def("dog_bark", [](const Dog &dog) { return dog.bark(); });
  87. // test_automatic_upcasting
  88. struct BaseClass {
  89. BaseClass() = default;
  90. BaseClass(const BaseClass &) = default;
  91. BaseClass(BaseClass &&) = default;
  92. virtual ~BaseClass() = default;
  93. };
  94. struct DerivedClass1 : BaseClass { };
  95. struct DerivedClass2 : BaseClass { };
  96. py::class_<BaseClass>(m, "BaseClass").def(py::init<>());
  97. py::class_<DerivedClass1>(m, "DerivedClass1").def(py::init<>());
  98. py::class_<DerivedClass2>(m, "DerivedClass2").def(py::init<>());
  99. m.def("return_class_1", []() -> BaseClass* { return new DerivedClass1(); });
  100. m.def("return_class_2", []() -> BaseClass* { return new DerivedClass2(); });
  101. m.def("return_class_n", [](int n) -> BaseClass* {
  102. if (n == 1) return new DerivedClass1();
  103. if (n == 2) return new DerivedClass2();
  104. return new BaseClass();
  105. });
  106. m.def("return_none", []() -> BaseClass* { return nullptr; });
  107. // test_isinstance
  108. m.def("check_instances", [](py::list l) {
  109. return py::make_tuple(
  110. py::isinstance<py::tuple>(l[0]),
  111. py::isinstance<py::dict>(l[1]),
  112. py::isinstance<Pet>(l[2]),
  113. py::isinstance<Pet>(l[3]),
  114. py::isinstance<Dog>(l[4]),
  115. py::isinstance<Rabbit>(l[5]),
  116. py::isinstance<UnregisteredType>(l[6])
  117. );
  118. });
  119. struct Invalid {};
  120. // test_type
  121. m.def("check_type", [](int category) {
  122. // Currently not supported (via a fail at compile time)
  123. // See https://github.com/pybind/pybind11/issues/2486
  124. // if (category == 2)
  125. // return py::type::of<int>();
  126. if (category == 1)
  127. return py::type::of<DerivedClass1>();
  128. else
  129. return py::type::of<Invalid>();
  130. });
  131. m.def("get_type_of", [](py::object ob) {
  132. return py::type::of(ob);
  133. });
  134. m.def("get_type_classic", [](py::handle h) {
  135. return h.get_type();
  136. });
  137. m.def("as_type", [](py::object ob) {
  138. return py::type(ob);
  139. });
  140. // test_mismatched_holder
  141. struct MismatchBase1 { };
  142. struct MismatchDerived1 : MismatchBase1 { };
  143. struct MismatchBase2 { };
  144. struct MismatchDerived2 : MismatchBase2 { };
  145. m.def("mismatched_holder_1", []() {
  146. auto mod = py::module_::import("__main__");
  147. py::class_<MismatchBase1, std::shared_ptr<MismatchBase1>>(mod, "MismatchBase1");
  148. py::class_<MismatchDerived1, MismatchBase1>(mod, "MismatchDerived1");
  149. });
  150. m.def("mismatched_holder_2", []() {
  151. auto mod = py::module_::import("__main__");
  152. py::class_<MismatchBase2>(mod, "MismatchBase2");
  153. py::class_<MismatchDerived2, std::shared_ptr<MismatchDerived2>,
  154. MismatchBase2>(mod, "MismatchDerived2");
  155. });
  156. // test_override_static
  157. // #511: problem with inheritance + overwritten def_static
  158. struct MyBase {
  159. static std::unique_ptr<MyBase> make() {
  160. return std::unique_ptr<MyBase>(new MyBase());
  161. }
  162. };
  163. struct MyDerived : MyBase {
  164. static std::unique_ptr<MyDerived> make() {
  165. return std::unique_ptr<MyDerived>(new MyDerived());
  166. }
  167. };
  168. py::class_<MyBase>(m, "MyBase")
  169. .def_static("make", &MyBase::make);
  170. py::class_<MyDerived, MyBase>(m, "MyDerived")
  171. .def_static("make", &MyDerived::make)
  172. .def_static("make2", &MyDerived::make);
  173. // test_implicit_conversion_life_support
  174. struct ConvertibleFromUserType {
  175. int i;
  176. ConvertibleFromUserType(UserType u) : i(u.value()) { }
  177. };
  178. py::class_<ConvertibleFromUserType>(m, "AcceptsUserType")
  179. .def(py::init<UserType>());
  180. py::implicitly_convertible<UserType, ConvertibleFromUserType>();
  181. m.def("implicitly_convert_argument", [](const ConvertibleFromUserType &r) { return r.i; });
  182. m.def("implicitly_convert_variable", [](py::object o) {
  183. // `o` is `UserType` and `r` is a reference to a temporary created by implicit
  184. // conversion. This is valid when called inside a bound function because the temp
  185. // object is attached to the same life support system as the arguments.
  186. const auto &r = o.cast<const ConvertibleFromUserType &>();
  187. return r.i;
  188. });
  189. m.add_object("implicitly_convert_variable_fail", [&] {
  190. auto f = [](PyObject *, PyObject *args) -> PyObject * {
  191. auto o = py::reinterpret_borrow<py::tuple>(args)[0];
  192. try { // It should fail here because there is no life support.
  193. o.cast<const ConvertibleFromUserType &>();
  194. } catch (const py::cast_error &e) {
  195. return py::str(e.what()).release().ptr();
  196. }
  197. return py::str().release().ptr();
  198. };
  199. auto def = new PyMethodDef{"f", f, METH_VARARGS, nullptr};
  200. py::capsule def_capsule(def, [](void *ptr) { delete reinterpret_cast<PyMethodDef *>(ptr); });
  201. return py::reinterpret_steal<py::object>(PyCFunction_NewEx(def, def_capsule.ptr(), m.ptr()));
  202. }());
  203. // test_operator_new_delete
  204. struct HasOpNewDel {
  205. std::uint64_t i;
  206. static void *operator new(size_t s) { py::print("A new", s); return ::operator new(s); }
  207. static void *operator new(size_t s, void *ptr) { py::print("A placement-new", s); return ptr; }
  208. static void operator delete(void *p) { py::print("A delete"); return ::operator delete(p); }
  209. };
  210. struct HasOpNewDelSize {
  211. std::uint32_t i;
  212. static void *operator new(size_t s) { py::print("B new", s); return ::operator new(s); }
  213. static void *operator new(size_t s, void *ptr) { py::print("B placement-new", s); return ptr; }
  214. static void operator delete(void *p, size_t s) { py::print("B delete", s); return ::operator delete(p); }
  215. };
  216. struct AliasedHasOpNewDelSize {
  217. std::uint64_t i;
  218. static void *operator new(size_t s) { py::print("C new", s); return ::operator new(s); }
  219. static void *operator new(size_t s, void *ptr) { py::print("C placement-new", s); return ptr; }
  220. static void operator delete(void *p, size_t s) { py::print("C delete", s); return ::operator delete(p); }
  221. virtual ~AliasedHasOpNewDelSize() = default;
  222. AliasedHasOpNewDelSize() = default;
  223. AliasedHasOpNewDelSize(const AliasedHasOpNewDelSize&) = delete;
  224. };
  225. struct PyAliasedHasOpNewDelSize : AliasedHasOpNewDelSize {
  226. PyAliasedHasOpNewDelSize() = default;
  227. PyAliasedHasOpNewDelSize(int) { }
  228. std::uint64_t j;
  229. };
  230. struct HasOpNewDelBoth {
  231. std::uint32_t i[8];
  232. static void *operator new(size_t s) { py::print("D new", s); return ::operator new(s); }
  233. static void *operator new(size_t s, void *ptr) { py::print("D placement-new", s); return ptr; }
  234. static void operator delete(void *p) { py::print("D delete"); return ::operator delete(p); }
  235. static void operator delete(void *p, size_t s) { py::print("D wrong delete", s); return ::operator delete(p); }
  236. };
  237. py::class_<HasOpNewDel>(m, "HasOpNewDel").def(py::init<>());
  238. py::class_<HasOpNewDelSize>(m, "HasOpNewDelSize").def(py::init<>());
  239. py::class_<HasOpNewDelBoth>(m, "HasOpNewDelBoth").def(py::init<>());
  240. py::class_<AliasedHasOpNewDelSize, PyAliasedHasOpNewDelSize> aliased(m, "AliasedHasOpNewDelSize");
  241. aliased.def(py::init<>());
  242. aliased.attr("size_noalias") = py::int_(sizeof(AliasedHasOpNewDelSize));
  243. aliased.attr("size_alias") = py::int_(sizeof(PyAliasedHasOpNewDelSize));
  244. // This test is actually part of test_local_bindings (test_duplicate_local), but we need a
  245. // definition in a different compilation unit within the same module:
  246. bind_local<LocalExternal, 17>(m, "LocalExternal", py::module_local());
  247. // test_bind_protected_functions
  248. class ProtectedA {
  249. protected:
  250. int foo() const { return value; }
  251. private:
  252. int value = 42;
  253. };
  254. class PublicistA : public ProtectedA {
  255. public:
  256. using ProtectedA::foo;
  257. };
  258. py::class_<ProtectedA>(m, "ProtectedA")
  259. .def(py::init<>())
  260. #if !defined(_MSC_VER) || _MSC_VER >= 1910
  261. .def("foo", &PublicistA::foo);
  262. #else
  263. .def("foo", static_cast<int (ProtectedA::*)() const>(&PublicistA::foo));
  264. #endif
  265. class ProtectedB {
  266. public:
  267. virtual ~ProtectedB() = default;
  268. ProtectedB() = default;
  269. ProtectedB(const ProtectedB &) = delete;
  270. protected:
  271. virtual int foo() const { return value; }
  272. private:
  273. int value = 42;
  274. };
  275. class TrampolineB : public ProtectedB {
  276. public:
  277. int foo() const override { PYBIND11_OVERRIDE(int, ProtectedB, foo, ); }
  278. };
  279. class PublicistB : public ProtectedB {
  280. public:
  281. // [workaround(intel)] = default does not work here
  282. // Removing or defaulting this destructor results in linking errors with the Intel compiler
  283. // (in Debug builds only, tested with icpc (ICC) 2021.1 Beta 20200827)
  284. ~PublicistB() override {}; // NOLINT(modernize-use-equals-default)
  285. using ProtectedB::foo;
  286. };
  287. py::class_<ProtectedB, TrampolineB>(m, "ProtectedB")
  288. .def(py::init<>())
  289. #if !defined(_MSC_VER) || _MSC_VER >= 1910
  290. .def("foo", &PublicistB::foo);
  291. #else
  292. .def("foo", static_cast<int (ProtectedB::*)() const>(&PublicistB::foo));
  293. #endif
  294. // test_brace_initialization
  295. struct BraceInitialization {
  296. int field1;
  297. std::string field2;
  298. };
  299. py::class_<BraceInitialization>(m, "BraceInitialization")
  300. .def(py::init<int, const std::string &>())
  301. .def_readwrite("field1", &BraceInitialization::field1)
  302. .def_readwrite("field2", &BraceInitialization::field2);
  303. // We *don't* want to construct using braces when the given constructor argument maps to a
  304. // constructor, because brace initialization could go to the wrong place (in particular when
  305. // there is also an `initializer_list<T>`-accept constructor):
  306. py::class_<NoBraceInitialization>(m, "NoBraceInitialization")
  307. .def(py::init<std::vector<int>>())
  308. .def_readonly("vec", &NoBraceInitialization::vec);
  309. // test_reentrant_implicit_conversion_failure
  310. // #1035: issue with runaway reentrant implicit conversion
  311. struct BogusImplicitConversion {
  312. BogusImplicitConversion(const BogusImplicitConversion &) = default;
  313. };
  314. py::class_<BogusImplicitConversion>(m, "BogusImplicitConversion")
  315. .def(py::init<const BogusImplicitConversion &>());
  316. py::implicitly_convertible<int, BogusImplicitConversion>();
  317. // test_qualname
  318. // #1166: nested class docstring doesn't show nested name
  319. // Also related: tests that __qualname__ is set properly
  320. struct NestBase {};
  321. struct Nested {};
  322. py::class_<NestBase> base(m, "NestBase");
  323. base.def(py::init<>());
  324. py::class_<Nested>(base, "Nested")
  325. .def(py::init<>())
  326. .def("fn", [](Nested &, int, NestBase &, Nested &) {})
  327. .def("fa", [](Nested &, int, NestBase &, Nested &) {},
  328. "a"_a, "b"_a, "c"_a);
  329. base.def("g", [](NestBase &, Nested &) {});
  330. base.def("h", []() { return NestBase(); });
  331. // test_error_after_conversion
  332. // The second-pass path through dispatcher() previously didn't
  333. // remember which overload was used, and would crash trying to
  334. // generate a useful error message
  335. struct NotRegistered {};
  336. struct StringWrapper { std::string str; };
  337. m.def("test_error_after_conversions", [](int) {});
  338. m.def("test_error_after_conversions",
  339. [](StringWrapper) -> NotRegistered { return {}; });
  340. py::class_<StringWrapper>(m, "StringWrapper").def(py::init<std::string>());
  341. py::implicitly_convertible<std::string, StringWrapper>();
  342. #if defined(PYBIND11_CPP17)
  343. struct alignas(1024) Aligned {
  344. std::uintptr_t ptr() const { return (uintptr_t) this; }
  345. };
  346. py::class_<Aligned>(m, "Aligned")
  347. .def(py::init<>())
  348. .def("ptr", &Aligned::ptr);
  349. #endif
  350. // test_final
  351. struct IsFinal final {};
  352. py::class_<IsFinal>(m, "IsFinal", py::is_final());
  353. // test_non_final_final
  354. struct IsNonFinalFinal {};
  355. py::class_<IsNonFinalFinal>(m, "IsNonFinalFinal", py::is_final());
  356. // test_exception_rvalue_abort
  357. struct PyPrintDestructor {
  358. PyPrintDestructor() = default;
  359. ~PyPrintDestructor() {
  360. py::print("Print from destructor");
  361. }
  362. void throw_something() { throw std::runtime_error("error"); }
  363. };
  364. py::class_<PyPrintDestructor>(m, "PyPrintDestructor")
  365. .def(py::init<>())
  366. .def("throw_something", &PyPrintDestructor::throw_something);
  367. // test_multiple_instances_with_same_pointer
  368. struct SamePointer {};
  369. static SamePointer samePointer;
  370. py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer")
  371. .def(py::init([]() { return &samePointer; }));
  372. struct Empty {};
  373. py::class_<Empty>(m, "Empty")
  374. .def(py::init<>());
  375. // test_base_and_derived_nested_scope
  376. struct BaseWithNested {
  377. struct Nested {};
  378. };
  379. struct DerivedWithNested : BaseWithNested {
  380. struct Nested {};
  381. };
  382. py::class_<BaseWithNested> baseWithNested_class(m, "BaseWithNested");
  383. py::class_<DerivedWithNested, BaseWithNested> derivedWithNested_class(m, "DerivedWithNested");
  384. py::class_<BaseWithNested::Nested>(baseWithNested_class, "Nested")
  385. .def_static("get_name", []() { return "BaseWithNested::Nested"; });
  386. py::class_<DerivedWithNested::Nested>(derivedWithNested_class, "Nested")
  387. .def_static("get_name", []() { return "DerivedWithNested::Nested"; });
  388. // test_register_duplicate_class
  389. struct Duplicate {};
  390. struct OtherDuplicate {};
  391. struct DuplicateNested {};
  392. struct OtherDuplicateNested {};
  393. m.def("register_duplicate_class_name", [](py::module_ m) {
  394. py::class_<Duplicate>(m, "Duplicate");
  395. py::class_<OtherDuplicate>(m, "Duplicate");
  396. });
  397. m.def("register_duplicate_class_type", [](py::module_ m) {
  398. py::class_<OtherDuplicate>(m, "OtherDuplicate");
  399. py::class_<OtherDuplicate>(m, "YetAnotherDuplicate");
  400. });
  401. m.def("register_duplicate_nested_class_name", [](py::object gt) {
  402. py::class_<DuplicateNested>(gt, "DuplicateNested");
  403. py::class_<OtherDuplicateNested>(gt, "DuplicateNested");
  404. });
  405. m.def("register_duplicate_nested_class_type", [](py::object gt) {
  406. py::class_<OtherDuplicateNested>(gt, "OtherDuplicateNested");
  407. py::class_<OtherDuplicateNested>(gt, "YetAnotherDuplicateNested");
  408. });
  409. }
  410. template <int N> class BreaksBase { public:
  411. virtual ~BreaksBase() = default;
  412. BreaksBase() = default;
  413. BreaksBase(const BreaksBase&) = delete;
  414. };
  415. template <int N> class BreaksTramp : public BreaksBase<N> {};
  416. // These should all compile just fine:
  417. using DoesntBreak1 = py::class_<BreaksBase<1>, std::unique_ptr<BreaksBase<1>>, BreaksTramp<1>>;
  418. using DoesntBreak2 = py::class_<BreaksBase<2>, BreaksTramp<2>, std::unique_ptr<BreaksBase<2>>>;
  419. using DoesntBreak3 = py::class_<BreaksBase<3>, std::unique_ptr<BreaksBase<3>>>;
  420. using DoesntBreak4 = py::class_<BreaksBase<4>, BreaksTramp<4>>;
  421. using DoesntBreak5 = py::class_<BreaksBase<5>>;
  422. using DoesntBreak6 = py::class_<BreaksBase<6>, std::shared_ptr<BreaksBase<6>>, BreaksTramp<6>>;
  423. using DoesntBreak7 = py::class_<BreaksBase<7>, BreaksTramp<7>, std::shared_ptr<BreaksBase<7>>>;
  424. using DoesntBreak8 = py::class_<BreaksBase<8>, std::shared_ptr<BreaksBase<8>>>;
  425. #define CHECK_BASE(N) static_assert(std::is_same<typename DoesntBreak##N::type, BreaksBase<N>>::value, \
  426. "DoesntBreak" #N " has wrong type!")
  427. CHECK_BASE(1); CHECK_BASE(2); CHECK_BASE(3); CHECK_BASE(4); CHECK_BASE(5); CHECK_BASE(6); CHECK_BASE(7); CHECK_BASE(8);
  428. #define CHECK_ALIAS(N) static_assert(DoesntBreak##N::has_alias && std::is_same<typename DoesntBreak##N::type_alias, BreaksTramp<N>>::value, \
  429. "DoesntBreak" #N " has wrong type_alias!")
  430. #define CHECK_NOALIAS(N) static_assert(!DoesntBreak##N::has_alias && std::is_void<typename DoesntBreak##N::type_alias>::value, \
  431. "DoesntBreak" #N " has type alias, but shouldn't!")
  432. CHECK_ALIAS(1); CHECK_ALIAS(2); CHECK_NOALIAS(3); CHECK_ALIAS(4); CHECK_NOALIAS(5); CHECK_ALIAS(6); CHECK_ALIAS(7); CHECK_NOALIAS(8);
  433. #define CHECK_HOLDER(N, TYPE) static_assert(std::is_same<typename DoesntBreak##N::holder_type, std::TYPE##_ptr<BreaksBase<N>>>::value, \
  434. "DoesntBreak" #N " has wrong holder_type!")
  435. CHECK_HOLDER(1, unique); CHECK_HOLDER(2, unique); CHECK_HOLDER(3, unique); CHECK_HOLDER(4, unique); CHECK_HOLDER(5, unique);
  436. CHECK_HOLDER(6, shared); CHECK_HOLDER(7, shared); CHECK_HOLDER(8, shared);
  437. // There's no nice way to test that these fail because they fail to compile; leave them here,
  438. // though, so that they can be manually tested by uncommenting them (and seeing that compilation
  439. // failures occurs).
  440. // We have to actually look into the type: the typedef alone isn't enough to instantiate the type:
  441. #define CHECK_BROKEN(N) static_assert(std::is_same<typename Breaks##N::type, BreaksBase<-N>>::value, \
  442. "Breaks1 has wrong type!");
  443. //// Two holder classes:
  444. //typedef py::class_<BreaksBase<-1>, std::unique_ptr<BreaksBase<-1>>, std::unique_ptr<BreaksBase<-1>>> Breaks1;
  445. //CHECK_BROKEN(1);
  446. //// Two aliases:
  447. //typedef py::class_<BreaksBase<-2>, BreaksTramp<-2>, BreaksTramp<-2>> Breaks2;
  448. //CHECK_BROKEN(2);
  449. //// Holder + 2 aliases
  450. //typedef py::class_<BreaksBase<-3>, std::unique_ptr<BreaksBase<-3>>, BreaksTramp<-3>, BreaksTramp<-3>> Breaks3;
  451. //CHECK_BROKEN(3);
  452. //// Alias + 2 holders
  453. //typedef py::class_<BreaksBase<-4>, std::unique_ptr<BreaksBase<-4>>, BreaksTramp<-4>, std::shared_ptr<BreaksBase<-4>>> Breaks4;
  454. //CHECK_BROKEN(4);
  455. //// Invalid option (not a subclass or holder)
  456. //typedef py::class_<BreaksBase<-5>, BreaksTramp<-4>> Breaks5;
  457. //CHECK_BROKEN(5);
  458. //// Invalid option: multiple inheritance not supported:
  459. //template <> struct BreaksBase<-8> : BreaksBase<-6>, BreaksBase<-7> {};
  460. //typedef py::class_<BreaksBase<-8>, BreaksBase<-6>, BreaksBase<-7>> Breaks8;
  461. //CHECK_BROKEN(8);