From f2dc5782efe6cd13c237a822f0fdece1f75b9246 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sun, 16 Feb 2025 10:16:40 +0100 Subject: [PATCH 1/7] CI: Fail on any warnings with clang 18 --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bfd4ca7287..ba364d0662 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -330,9 +330,10 @@ jobs: container_suffix: "-bullseye" - clang: 18 std: 20 + cxx_flags: "-Werror -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls" container_suffix: "-bookworm" - name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64" + name: "🐍 3 • Clang ${{ matrix.clang }} • C++${{ matrix.std }} • x64${{ matrix.cxx_flags && ' • cxx_flags' || '' }}" container: "silkeh/clang:${{ matrix.clang }}${{ matrix.container_suffix }}" steps: @@ -348,6 +349,7 @@ jobs: -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }} + -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - name: Build From a77a7c39c412da2a2893fcaa173ec929693e5105 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Tue, 29 Apr 2025 15:49:03 +0200 Subject: [PATCH 2/7] CI: Fail on any warnings with gcc 13 --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba364d0662..a316efadcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -493,9 +493,9 @@ jobs: - { gcc: 9, std: 20 } - { gcc: 10, std: 17 } - { gcc: 10, std: 20 } - - { gcc: 13, std: 20 } + - { gcc: 13, std: 20, cxx_flags: "-Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls" } - name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }}• x64" + name: "🐍 3 • GCC ${{ matrix.gcc }} • C++${{ matrix.std }} • x64${{ matrix.cxx_flags && ' • cxx_flags' || '' }}" container: "gcc:${{ matrix.gcc }}" steps: @@ -517,6 +517,7 @@ jobs: -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }} + -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" -DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") - name: Build From df1462f0a9fbf7fd9fdf9e3a5ca281fb623f01e8 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sun, 16 Feb 2025 11:02:51 +0100 Subject: [PATCH 3/7] Fix cmake's try_compile warning --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e5e613df48..69976f745a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -363,7 +363,7 @@ elseif(MSVC) else() file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp - "#include \nint main(int argc, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}" + "#include \nint main(int /*argc*/, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}" ) try_compile( STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR} From 42c35080ad525d2af63ab25be1de5a9181f0b2a3 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 15 Feb 2025 22:19:33 +0100 Subject: [PATCH 4/7] Guard redundant declarations --- include/pybind11/detail/class.h | 5 +++++ include/pybind11/gil.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 98ff61f5d7..fbba3edafe 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -499,8 +499,13 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) { Py_DECREF(type); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" + std::string error_string(); +#pragma GCC diagnostic pop + /** Create the type which can be used as a common base for all classes. This is needed in order to satisfy Python's requirements for multiple inheritance. Return value: New reference. */ diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h index 3f2c28f452..040fc66884 100644 --- a/include/pybind11/gil.h +++ b/include/pybind11/gil.h @@ -32,9 +32,14 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" + // forward declarations PyThreadState *get_thread_state_unchecked(); +#pragma GCC diagnostic pop + PYBIND11_NAMESPACE_END(detail) /* The functions below essentially reproduce the PyGILState_* API using a RAII From a3bf977e552c1320036eded81735b40bb224ab66 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sun, 16 Feb 2025 11:07:55 +0100 Subject: [PATCH 5/7] ci.yml: fix syntax error --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a316efadcd..7b80a91a16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,7 +199,7 @@ jobs: run: | uv pip install --python=python --system setuptools pytest tests/extra_setuptools - if: "!(matrix.runs-on == 'windows-2022')" + if: matrix.runs-on != 'windows-2022' manylinux: name: Manylinux on 🐍 3.13t • GIL From 23f3ef071baaecd547af22803fa91c6d1b6c069d Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 22 Feb 2025 20:18:04 +0100 Subject: [PATCH 6/7] Use PYBIND11_WARNING macros --- include/pybind11/detail/class.h | 6 +++--- include/pybind11/gil.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index fbba3edafe..08e26f71d0 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -499,12 +499,12 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) { Py_DECREF(type); } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wredundant-decls" +PYBIND11_WARNING_PUSH +PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls") std::string error_string(); -#pragma GCC diagnostic pop +PYBIND11_WARNING_POP /** Create the type which can be used as a common base for all classes. This is needed in order to satisfy Python's requirements for multiple inheritance. diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h index 040fc66884..1a9bfeaddf 100644 --- a/include/pybind11/gil.h +++ b/include/pybind11/gil.h @@ -32,13 +32,13 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) PYBIND11_NAMESPACE_BEGIN(detail) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wredundant-decls" +PYBIND11_WARNING_PUSH +PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls") // forward declarations PyThreadState *get_thread_state_unchecked(); -#pragma GCC diagnostic pop +PYBIND11_WARNING_POP PYBIND11_NAMESPACE_END(detail) From e43db082a63fb24776884d407e8956199c71b89f Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Tue, 29 Apr 2025 17:18:01 +0200 Subject: [PATCH 7/7] Fix more redundant declarations ... introduced with merge of smart_holder branch --- include/pybind11/detail/function_record_pyobject.h | 3 --- include/pybind11/detail/type_caster_base.h | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/pybind11/detail/function_record_pyobject.h b/include/pybind11/detail/function_record_pyobject.h index 4cc8b242e8..13895b96f2 100644 --- a/include/pybind11/detail/function_record_pyobject.h +++ b/include/pybind11/detail/function_record_pyobject.h @@ -173,9 +173,6 @@ inline int tp_init_impl(PyObject *, PyObject *, PyObject *) { // return -1; // Unreachable. } -// The implementation needs the definition of `class cpp_function`. -void tp_dealloc_impl(PyObject *self); - inline void tp_free_impl(void *) { pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_free_impl"); } diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index d4f9a41e0c..d4ce1a492a 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -511,9 +511,14 @@ inline PyThreadState *get_thread_state_unchecked() { void keep_alive_impl(handle nurse, handle patient); inline PyObject *make_new_instance(PyTypeObject *type); +PYBIND11_WARNING_PUSH +PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls") + // PYBIND11:REMINDER: Needs refactoring of existing pybind11 code. inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo); +PYBIND11_WARNING_POP + PYBIND11_NAMESPACE_BEGIN(smart_holder_type_caster_support) struct value_and_holder_helper {