mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Fix gcc compiler warnings (#5523)
* CI: Fail on any warnings with clang 18 * CI: Fail on any warnings with gcc 13 * Fix cmake's try_compile warning * Guard redundant declarations * ci.yml: fix syntax error * Use PYBIND11_WARNING macros * Fix more redundant declarations ... introduced with merge of smart_holder branch
This commit is contained in:
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@@ -199,7 +199,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
uv pip install --python=python --system setuptools
|
uv pip install --python=python --system setuptools
|
||||||
pytest tests/extra_setuptools
|
pytest tests/extra_setuptools
|
||||||
if: "!(matrix.runs-on == 'windows-2022')"
|
if: matrix.runs-on != 'windows-2022'
|
||||||
|
|
||||||
manylinux:
|
manylinux:
|
||||||
name: Manylinux on 🐍 3.13t • GIL
|
name: Manylinux on 🐍 3.13t • GIL
|
||||||
@@ -330,9 +330,10 @@ jobs:
|
|||||||
container_suffix: "-bullseye"
|
container_suffix: "-bullseye"
|
||||||
- clang: 18
|
- clang: 18
|
||||||
std: 20
|
std: 20
|
||||||
|
cxx_flags: "-Werror -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls"
|
||||||
container_suffix: "-bookworm"
|
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 }}"
|
container: "silkeh/clang:${{ matrix.clang }}${{ matrix.container_suffix }}"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -348,6 +349,7 @@ jobs:
|
|||||||
-DPYBIND11_WERROR=ON
|
-DPYBIND11_WERROR=ON
|
||||||
-DDOWNLOAD_CATCH=ON
|
-DDOWNLOAD_CATCH=ON
|
||||||
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
|
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
|
||||||
|
-DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
|
||||||
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
|
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -491,9 +493,9 @@ jobs:
|
|||||||
- { gcc: 9, std: 20 }
|
- { gcc: 9, std: 20 }
|
||||||
- { gcc: 10, std: 17 }
|
- { gcc: 10, std: 17 }
|
||||||
- { gcc: 10, std: 20 }
|
- { 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 }}"
|
container: "gcc:${{ matrix.gcc }}"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -515,6 +517,7 @@ jobs:
|
|||||||
-DPYBIND11_WERROR=ON
|
-DPYBIND11_WERROR=ON
|
||||||
-DDOWNLOAD_CATCH=ON
|
-DDOWNLOAD_CATCH=ON
|
||||||
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
|
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
|
||||||
|
-DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
|
||||||
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
|
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|||||||
@@ -499,8 +499,13 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
|
|||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PYBIND11_WARNING_PUSH
|
||||||
|
PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls")
|
||||||
|
|
||||||
std::string error_string();
|
std::string error_string();
|
||||||
|
|
||||||
|
PYBIND11_WARNING_POP
|
||||||
|
|
||||||
/** Create the type which can be used as a common base for all classes. This is
|
/** 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.
|
needed in order to satisfy Python's requirements for multiple inheritance.
|
||||||
Return value: New reference. */
|
Return value: New reference. */
|
||||||
|
|||||||
@@ -173,9 +173,6 @@ inline int tp_init_impl(PyObject *, PyObject *, PyObject *) {
|
|||||||
// return -1; // Unreachable.
|
// return -1; // Unreachable.
|
||||||
}
|
}
|
||||||
|
|
||||||
// The implementation needs the definition of `class cpp_function`.
|
|
||||||
void tp_dealloc_impl(PyObject *self);
|
|
||||||
|
|
||||||
inline void tp_free_impl(void *) {
|
inline void tp_free_impl(void *) {
|
||||||
pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_free_impl");
|
pybind11_fail("UNEXPECTED CALL OF function_record_PyTypeObject_methods::tp_free_impl");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -511,9 +511,14 @@ inline PyThreadState *get_thread_state_unchecked() {
|
|||||||
void keep_alive_impl(handle nurse, handle patient);
|
void keep_alive_impl(handle nurse, handle patient);
|
||||||
inline PyObject *make_new_instance(PyTypeObject *type);
|
inline PyObject *make_new_instance(PyTypeObject *type);
|
||||||
|
|
||||||
|
PYBIND11_WARNING_PUSH
|
||||||
|
PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls")
|
||||||
|
|
||||||
// PYBIND11:REMINDER: Needs refactoring of existing pybind11 code.
|
// PYBIND11:REMINDER: Needs refactoring of existing pybind11 code.
|
||||||
inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo);
|
inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo);
|
||||||
|
|
||||||
|
PYBIND11_WARNING_POP
|
||||||
|
|
||||||
PYBIND11_NAMESPACE_BEGIN(smart_holder_type_caster_support)
|
PYBIND11_NAMESPACE_BEGIN(smart_holder_type_caster_support)
|
||||||
|
|
||||||
struct value_and_holder_helper {
|
struct value_and_holder_helper {
|
||||||
|
|||||||
@@ -32,9 +32,14 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|||||||
|
|
||||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||||
|
|
||||||
|
PYBIND11_WARNING_PUSH
|
||||||
|
PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls")
|
||||||
|
|
||||||
// forward declarations
|
// forward declarations
|
||||||
PyThreadState *get_thread_state_unchecked();
|
PyThreadState *get_thread_state_unchecked();
|
||||||
|
|
||||||
|
PYBIND11_WARNING_POP
|
||||||
|
|
||||||
PYBIND11_NAMESPACE_END(detail)
|
PYBIND11_NAMESPACE_END(detail)
|
||||||
|
|
||||||
/* The functions below essentially reproduce the PyGILState_* API using a RAII
|
/* The functions below essentially reproduce the PyGILState_* API using a RAII
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ elseif(MSVC)
|
|||||||
else()
|
else()
|
||||||
file(
|
file(
|
||||||
WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
|
WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp
|
||||||
"#include <filesystem>\nint main(int argc, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}"
|
"#include <filesystem>\nint main(int /*argc*/, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}"
|
||||||
)
|
)
|
||||||
try_compile(
|
try_compile(
|
||||||
STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
|
STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
|||||||
Reference in New Issue
Block a user