Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gcc compiler warnings #5523

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ jobs:
run: |
pip install setuptools
pytest tests/extra_setuptools
if: "!(matrix.runs-on == 'windows-2022')"
if: matrix.runs-on != 'windows-2022'

manylinux:
name: Manylinux on 🐍 3.13t • GIL
Expand Down Expand Up @@ -360,9 +360,10 @@ jobs:
container_suffix: "-bookworm"
- 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:
Expand All @@ -378,6 +379,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
Expand Down Expand Up @@ -521,11 +523,11 @@ jobs:
- { gcc: 9, std: 20 }
- { gcc: 10, std: 17 }
- { gcc: 10, std: 20 }
- { gcc: 11, std: 20 }
- { gcc: 11, std: 20, cxx_flags: "-Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls" }
- { gcc: 12, 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:
Expand All @@ -547,6 +549,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
Expand Down
5 changes: 5 additions & 0 deletions include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,13 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
Py_DECREF(type);
}

PYBIND11_WARNING_PUSH
PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls")

std::string error_string();

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.
Return value: New reference. */
Expand Down
5 changes: 5 additions & 0 deletions include/pybind11/gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

PYBIND11_NAMESPACE_BEGIN(detail)

PYBIND11_WARNING_PUSH
PYBIND11_WARNING_DISABLE_GCC("-Wredundant-decls")

// forward declarations
PyThreadState *get_thread_state_unchecked();

PYBIND11_WARNING_POP

PYBIND11_NAMESPACE_END(detail)

#if !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ elseif(MSVC)
else()
file(
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(
STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR}
Expand Down
Loading