MCPcopy Create free account
hub / github.com/pybind/pybind11 / PYBIND11_OVERRIDE

Function PYBIND11_OVERRIDE

tests/test_class.cpp:433–599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

431 public:
432 int foo() const override { PYBIND11_OVERRIDE(int, ProtectedB, foo, ); }
433 void *void_foo() override { PYBIND11_OVERRIDE(void *, ProtectedB, void_foo, ); }
434 void *get_self() override { PYBIND11_OVERRIDE(void *, ProtectedB, get_self, ); }
435 };
436
437 class PublicistB : public ProtectedB {
438 public:
439 // [workaround(intel)] = default does not work here
440 // Removing or defaulting this destructor results in linking errors with the Intel compiler
441 // (in Debug builds only, tested with icpc (ICC) 2021.1 Beta 20200827)
442 ~PublicistB() override {}; // NOLINT(modernize-use-equals-default)
443 using ProtectedB::foo;
444 using ProtectedB::get_self;
445 using ProtectedB::void_foo;
446 };
447
448 m.def("read_foo", [](const void *original) {
449 const int *ptr = reinterpret_cast<const int *>(original);
450 return *ptr;
451 });
452
453 m.def("pointers_equal",
454 [](const void *original, const void *comparison) { return original == comparison; });
455
456 py::class_<ProtectedB, TrampolineB>(m, "ProtectedB")
457 .def(py::init<>())
458 .def("foo", &PublicistB::foo)
459 .def("void_foo", &PublicistB::void_foo)
460 .def("get_self", &PublicistB::get_self);
461
462 // test_brace_initialization
463 struct BraceInitialization {
464 int field1;
465 std::string field2;
466 };
467
468 py::class_<BraceInitialization>(m, "BraceInitialization")
469 .def(py::init<int, const std::string &>())
470 .def_readwrite("field1", &BraceInitialization::field1)
471 .def_readwrite("field2", &BraceInitialization::field2);
472 // We *don't* want to construct using braces when the given constructor argument maps to a
473 // constructor, because brace initialization could go to the wrong place (in particular when
474 // there is also an `initializer_list<T>`-accept constructor):
475 py::class_<NoBraceInitialization>(m, "NoBraceInitialization")
476 .def(py::init<std::vector<int>>())
477 .def_readonly("vec", &NoBraceInitialization::vec);
478
479 // test_reentrant_implicit_conversion_failure
480 // #1035: issue with runaway reentrant implicit conversion
481 struct BogusImplicitConversion {
482 BogusImplicitConversion(const BogusImplicitConversion &) = default;
483 };
484
485 py::class_<BogusImplicitConversion>(m, "BogusImplicitConversion")
486 .def(py::init<const BogusImplicitConversion &>());
487
488 py::implicitly_convertible<int, BogusImplicitConversion>();
489
490 // test_qualname

Callers

nothing calls this directly

Calls 4

NestBaseClass · 0.85
is_finalClass · 0.85
initFunction · 0.85
bind_empty0Function · 0.85

Tested by

no test coverage detected