From 3665530264bbfeb9ec7623635d7cc644a70116b3 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 1 Aug 2022 06:18:48 -0700 Subject: [PATCH] Add `-DPYBIND11_WERROR=ON` to mingw cmake commands (#4073) * Add `-DPYBIND11_WERROR=ON` to mingw cmake commands (and `-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON`). * Using no-destructor idiom to side-step overzealous MINGW warning. * Add __MINGW32__ pragma GCC diagnostic ignored in eigen.h * Add another no-destructor workaround. * Temporarily add -k (keep-going) flags to hopefully speed up finding all warnings. * Revert "Temporarily add -k (keep-going) flags to hopefully speed up finding all warnings." This reverts commit f36b0af8f93e9f6f16c969fb5b646e116f5eaf0f. * Very minor shuffle to avoid MSVC warnings. * Remove all `:BOOL` as suggested by @henryiii --- .github/workflows/ci.yml | 6 +++--- include/pybind11/eigen.h | 5 +++++ tests/test_builtin_casters.cpp | 9 +++++++-- tests/test_stl.cpp | 10 ++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a24ad6ab..ac6c536ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -911,7 +911,7 @@ jobs: - name: Configure C++11 # LTO leads to many undefined reference like # `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&) - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DDOWNLOAD_CATCH=ON -S . -B build + run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build - name: Build C++11 run: cmake --build build -j 2 @@ -929,7 +929,7 @@ jobs: run: git clean -fdx - name: Configure C++14 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DDOWNLOAD_CATCH=ON -S . -B build2 + run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2 - name: Build C++14 run: cmake --build build2 -j 2 @@ -947,7 +947,7 @@ jobs: run: git clean -fdx - name: Configure C++17 - run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DDOWNLOAD_CATCH=ON -S . -B build3 + run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3 - name: Build C++17 run: cmake --build build3 -j 2 diff --git a/include/pybind11/eigen.h b/include/pybind11/eigen.h index 4d221b3d7..831625229 100644 --- a/include/pybind11/eigen.h +++ b/include/pybind11/eigen.h @@ -27,6 +27,9 @@ # pragma warning(disable : 4127) // C4127: conditional expression is constant # pragma warning(disable : 5054) // https://github.com/pybind/pybind11/pull/3741 // C5054: operator '&': deprecated between enumerations of different types +#elif defined(__MINGW32__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif #include @@ -34,6 +37,8 @@ #if defined(_MSC_VER) # pragma warning(pop) +#elif defined(__MINGW32__) +# pragma GCC diagnostic pop #endif // Eigen prior to 3.2.7 doesn't have proper move constructors--but worse, some classes get implicit diff --git a/tests/test_builtin_casters.cpp b/tests/test_builtin_casters.cpp index 6529f47d0..6ff63edfc 100644 --- a/tests/test_builtin_casters.cpp +++ b/tests/test_builtin_casters.cpp @@ -266,9 +266,14 @@ TEST_SUBMODULE(builtin_casters, m) { }); m.def("lvalue_nested", []() -> const decltype(lvnested) & { return lvnested; }); - static std::pair int_string_pair{2, "items"}; m.def( - "int_string_pair", []() { return &int_string_pair; }, py::return_value_policy::reference); + "int_string_pair", + []() { + // Using no-destructor idiom to side-step warnings from overzealous compilers. + static auto *int_string_pair = new std::pair{2, "items"}; + return int_string_pair; + }, + py::return_value_policy::reference); // test_builtins_cast_return_none m.def("return_none_string", []() -> std::string * { return nullptr; }); diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index 38d32fda9..dcc92c3f0 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -176,9 +176,14 @@ TEST_SUBMODULE(stl, m) { m.def("load_bool_vector", [](const std::vector &v) { return v.at(0) == true && v.at(1) == false; }); // Unnumbered regression (caused by #936): pointers to stl containers aren't castable - static std::vector lvv{2}; m.def( - "cast_ptr_vector", []() { return &lvv; }, py::return_value_policy::reference); + "cast_ptr_vector", + []() { + // Using no-destructor idiom to side-step warnings from overzealous compilers. + static auto *v = new std::vector{2}; + return v; + }, + py::return_value_policy::reference); // test_deque m.def("cast_deque", []() { return std::deque{1}; }); @@ -237,6 +242,7 @@ TEST_SUBMODULE(stl, m) { lvn["b"].emplace_back(); // add a list lvn["b"].back().emplace_back(); // add an array lvn["b"].back().emplace_back(); // add another array + static std::vector lvv{2}; m.def("cast_lv_vector", []() -> const decltype(lvv) & { return lvv; }); m.def("cast_lv_array", []() -> const decltype(lva) & { return lva; }); m.def("cast_lv_map", []() -> const decltype(lvm) & { return lvm; });