Skip to content

Commit 3665530

Browse files
authored
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 f36b0af. * Very minor shuffle to avoid MSVC warnings. * Remove all `:BOOL` as suggested by @henryiii
1 parent 1e3400b commit 3665530

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ jobs:
911911
- name: Configure C++11
912912
# LTO leads to many undefined reference like
913913
# `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&)
914-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DDOWNLOAD_CATCH=ON -S . -B build
914+
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build
915915

916916
- name: Build C++11
917917
run: cmake --build build -j 2
@@ -929,7 +929,7 @@ jobs:
929929
run: git clean -fdx
930930

931931
- name: Configure C++14
932-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DDOWNLOAD_CATCH=ON -S . -B build2
932+
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build2
933933

934934
- name: Build C++14
935935
run: cmake --build build2 -j 2
@@ -947,7 +947,7 @@ jobs:
947947
run: git clean -fdx
948948

949949
- name: Configure C++17
950-
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DDOWNLOAD_CATCH=ON -S . -B build3
950+
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DCMAKE_VERBOSE_MAKEFILE=ON -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -S . -B build3
951951

952952
- name: Build C++17
953953
run: cmake --build build3 -j 2

include/pybind11/eigen.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@
2727
# pragma warning(disable : 4127) // C4127: conditional expression is constant
2828
# pragma warning(disable : 5054) // https://github.com/pybind/pybind11/pull/3741
2929
// C5054: operator '&': deprecated between enumerations of different types
30+
#elif defined(__MINGW32__)
31+
# pragma GCC diagnostic push
32+
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
3033
#endif
3134

3235
#include <Eigen/Core>
3336
#include <Eigen/SparseCore>
3437

3538
#if defined(_MSC_VER)
3639
# pragma warning(pop)
40+
#elif defined(__MINGW32__)
41+
# pragma GCC diagnostic pop
3742
#endif
3843

3944
// Eigen prior to 3.2.7 doesn't have proper move constructors--but worse, some classes get implicit

tests/test_builtin_casters.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,14 @@ TEST_SUBMODULE(builtin_casters, m) {
266266
});
267267
m.def("lvalue_nested", []() -> const decltype(lvnested) & { return lvnested; });
268268

269-
static std::pair<int, std::string> int_string_pair{2, "items"};
270269
m.def(
271-
"int_string_pair", []() { return &int_string_pair; }, py::return_value_policy::reference);
270+
"int_string_pair",
271+
[]() {
272+
// Using no-destructor idiom to side-step warnings from overzealous compilers.
273+
static auto *int_string_pair = new std::pair<int, std::string>{2, "items"};
274+
return int_string_pair;
275+
},
276+
py::return_value_policy::reference);
272277

273278
// test_builtins_cast_return_none
274279
m.def("return_none_string", []() -> std::string * { return nullptr; });

tests/test_stl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ TEST_SUBMODULE(stl, m) {
176176
m.def("load_bool_vector",
177177
[](const std::vector<bool> &v) { return v.at(0) == true && v.at(1) == false; });
178178
// Unnumbered regression (caused by #936): pointers to stl containers aren't castable
179-
static std::vector<RValueCaster> lvv{2};
180179
m.def(
181-
"cast_ptr_vector", []() { return &lvv; }, py::return_value_policy::reference);
180+
"cast_ptr_vector",
181+
[]() {
182+
// Using no-destructor idiom to side-step warnings from overzealous compilers.
183+
static auto *v = new std::vector<RValueCaster>{2};
184+
return v;
185+
},
186+
py::return_value_policy::reference);
182187

183188
// test_deque
184189
m.def("cast_deque", []() { return std::deque<int>{1}; });
@@ -237,6 +242,7 @@ TEST_SUBMODULE(stl, m) {
237242
lvn["b"].emplace_back(); // add a list
238243
lvn["b"].back().emplace_back(); // add an array
239244
lvn["b"].back().emplace_back(); // add another array
245+
static std::vector<RValueCaster> lvv{2};
240246
m.def("cast_lv_vector", []() -> const decltype(lvv) & { return lvv; });
241247
m.def("cast_lv_array", []() -> const decltype(lva) & { return lva; });
242248
m.def("cast_lv_map", []() -> const decltype(lvm) & { return lvm; });

0 commit comments

Comments
 (0)