Files
pybind11/tests/test_class_sh_virtual_py_cpp_mix.cpp
Henry Schreinerandpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> 652c69437b fix: add py::mod_gil_used() spelling, support pedantic tests (#5797)
* tests: add linking warnings/error

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: check pedantic C++14

* fix: some pedantic warnings

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* feat: add py::mod_gil_used()

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* fix: use not_supported()

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* style: pre-commit fixes

* Update CMakeLists.txt

* fix: remove the true/false parameter from mod_gil_not_used

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* style: pre-commit fixes

* Update tests/CMakeLists.txt

* fix: deprecate mod_gil_not_used(bool) instead of removing it

Keep the bool constructor public and mark it deprecated, so existing
code that spells mod_gil_not_used(false) still compiles. mod_gil_used()
now sets the flag through its friendship, which keeps the deprecated
constructor the only bool overload and stops pybind11 warning against
itself.

Also use the py:: alias in exo_planet_pybind11.cpp to match its sibling
home_planet_very_lonely_traveler.cpp.

Assisted-by: ClaudeCode:claude-opus-5

* fix: add trailing comma to macros picked up in rebase

test_smart_ptr.cpp and standalone_enum_module.cpp came from master after
this branch was written, so they still invoked variadic macros with no
variadic argument. That is a pedantic error below C++20.

Assisted-by: ClaudeCode:claude-opus-5

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-07-29 14:53:47 -04:00

59 lines
1.6 KiB
C++

#include "pybind11_tests.h"
#include <memory>
namespace pybind11_tests {
namespace class_sh_virtual_py_cpp_mix {
class Base {
public:
virtual ~Base() = default;
virtual int get() const { return 101; }
// Some compilers complain about implicitly defined versions of some of the following:
Base() = default;
Base(const Base &) = default;
};
class CppDerivedPlain : public Base {
public:
int get() const override { return 202; }
};
class CppDerived : public Base {
public:
int get() const override { return 212; }
};
int get_from_cpp_plainc_ptr(const Base *b) { return b->get() + 4000; }
int get_from_cpp_unique_ptr(std::unique_ptr<Base> b) { return b->get() + 5000; }
struct BaseVirtualOverrider : Base, py::trampoline_self_life_support {
using Base::Base;
int get() const override { PYBIND11_OVERRIDE(int, Base, get, ); }
};
struct CppDerivedVirtualOverrider : CppDerived, py::trampoline_self_life_support {
using CppDerived::CppDerived;
int get() const override { PYBIND11_OVERRIDE(int, CppDerived, get, ); }
};
} // namespace class_sh_virtual_py_cpp_mix
} // namespace pybind11_tests
using namespace pybind11_tests::class_sh_virtual_py_cpp_mix;
TEST_SUBMODULE(class_sh_virtual_py_cpp_mix, m) {
py::classh<Base, BaseVirtualOverrider>(m, "Base").def(py::init<>()).def("get", &Base::get);
py::classh<CppDerivedPlain, Base>(m, "CppDerivedPlain").def(py::init<>());
py::classh<CppDerived, Base, CppDerivedVirtualOverrider>(m, "CppDerived").def(py::init<>());
m.def("get_from_cpp_plainc_ptr", get_from_cpp_plainc_ptr, py::arg("b"));
m.def("get_from_cpp_unique_ptr", get_from_cpp_unique_ptr, py::arg("b"));
}