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