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>
This commit is contained in:
Henry Schreiner
2026-07-29 14:53:47 -04:00
committed by GitHub
co-authored by pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
parent 2f85cc8c4a
commit 652c69437b
15 changed files with 53 additions and 40 deletions
+8 -8
View File
@@ -219,7 +219,7 @@ public:
};
class test_override_cache_helper_trampoline : public test_override_cache_helper {
int func() override { PYBIND11_OVERRIDE(int, test_override_cache_helper, func); }
int func() override { PYBIND11_OVERRIDE(int, test_override_cache_helper, func, ); }
};
inline int test_override_cache(std::shared_ptr<test_override_cache_helper> const &instance) {
@@ -279,7 +279,7 @@ TEST_SUBMODULE(virtual_functions, m) {
py::print("PyA.f()");
// This convolution just gives a `void`, but tests that PYBIND11_TYPE() works to
// protect a type containing a ,
PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f);
PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f, );
}
};
@@ -302,7 +302,7 @@ TEST_SUBMODULE(virtual_functions, m) {
~PyA2() override { py::print("PyA2.~PyA2()"); }
void f() override {
py::print("PyA2.f()");
PYBIND11_OVERRIDE(void, A2, f);
PYBIND11_OVERRIDE(void, A2, f, );
}
};
@@ -370,26 +370,26 @@ TEST_SUBMODULE(virtual_functions, m) {
public:
using OverrideTest::OverrideTest;
std::string str_value() override {
PYBIND11_OVERRIDE(std::string, OverrideTest, str_value);
PYBIND11_OVERRIDE(std::string, OverrideTest, str_value, );
}
// Not allowed (enabling the below should hit a static_assert failure): we can't get a
// reference to a python numeric value, since we only copy values in the numeric type
// caster:
#ifdef PYBIND11_NEVER_DEFINED_EVER
std::string &str_ref() override {
PYBIND11_OVERRIDE(std::string &, OverrideTest, str_ref);
PYBIND11_OVERRIDE(std::string &, OverrideTest, str_ref, );
}
#endif
// But we can work around it like this:
private:
std::string _tmp;
std::string str_ref_helper() { PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref); }
std::string str_ref_helper() { PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref, ); }
public:
std::string &str_ref() override { return _tmp = str_ref_helper(); }
A A_value() override { PYBIND11_OVERRIDE(A, OverrideTest, A_value); }
A &A_ref() override { PYBIND11_OVERRIDE(A &, OverrideTest, A_ref); }
A A_value() override { PYBIND11_OVERRIDE(A, OverrideTest, A_value, ); }
A &A_ref() override { PYBIND11_OVERRIDE(A &, OverrideTest, A_ref, ); }
};
py::class_<OverrideTest::A>(m, "OverrideTest_A")