Skip to content

Commit 774b5ff

Browse files
authored
Removing obsolete eigen.h warning suppression pragmas. (#3198)
* Removing all pragma from eigen.h * Removing -Werror or equivalent from tests/CMakeLists.txt * Restoring tests/CMakeLists.txt from master. * Adding 4 PYBIND11_SILENCE_MSVC_C4127. * Compatibility with -Wconversion, -Wdeprecated * Introducing PYBIND11_COMPATIBILITY_WDEPRECATED_COPY * Systematically using --verbose for compilations where possible (cmake 3.14 or newer). Also changing all `cmake -t` to `--target`, `-v` to `--verbose`, `check` to `pytest`, for consistency (to make it easier to pin-point all commands of a certain type). Also removing one `-j 2` for `pytest` in hopes of reducing flakes due to races in test_iostream and in prints from destructors. * Commenting out pragmas as an experiment to reproduce previous observation. * Removing all (newly added, but already commented-out) pragma code, adding HINT use -isystem (as cmake does). * Restoring ci.yml from master. Those changes are better handled separately. BTW: in the last CI run there was still a test_iostream flake, even without the -j 2 for running the tests (verfied by inspecting the log).
1 parent 617cb65 commit 774b5ff

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

include/pybind11/eigen.h

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,13 @@
99

1010
#pragma once
1111

12-
#include "numpy.h"
13-
14-
#if defined(__INTEL_COMPILER)
15-
# pragma warning(disable: 1682) // implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
16-
#elif defined(__GNUG__) || defined(__clang__)
17-
# pragma GCC diagnostic push
18-
# pragma GCC diagnostic ignored "-Wconversion"
19-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20-
# ifdef __clang__
21-
// Eigen generates a bunch of implicit-copy-constructor-is-deprecated warnings with -Wdeprecated
22-
// under Clang, so disable that warning here:
23-
# pragma GCC diagnostic ignored "-Wdeprecated"
24-
# endif
25-
# if __GNUC__ >= 7
26-
# pragma GCC diagnostic ignored "-Wint-in-bool-context"
27-
# endif
28-
#endif
12+
/* HINT: To suppress warnings originating from the Eigen headers, use -isystem.
13+
See also:
14+
https://stackoverflow.com/questions/2579576/i-dir-vs-isystem-dir
15+
https://stackoverflow.com/questions/1741816/isystem-for-ms-visual-studio-c-compiler
16+
*/
2917

30-
#if defined(_MSC_VER)
31-
# pragma warning(push)
32-
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
33-
# pragma warning(disable: 4996) // warning C4996: std::unary_negate is deprecated in C++17
34-
#endif
18+
#include "numpy.h"
3519

3620
#include <Eigen/Core>
3721
#include <Eigen/SparseCore>
@@ -153,7 +137,8 @@ template <typename Type_> struct EigenProps {
153137
np_cols = a.shape(1),
154138
np_rstride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar)),
155139
np_cstride = a.strides(1) / static_cast<ssize_t>(sizeof(Scalar));
156-
if ((fixed_rows && np_rows != rows) || (fixed_cols && np_cols != cols))
140+
if ((PYBIND11_SILENCE_MSVC_C4127(fixed_rows) && np_rows != rows) ||
141+
(PYBIND11_SILENCE_MSVC_C4127(fixed_cols) && np_cols != cols))
157142
return false;
158143

159144
return {np_rows, np_cols, np_rstride, np_cstride};
@@ -165,7 +150,7 @@ template <typename Type_> struct EigenProps {
165150
stride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar));
166151

167152
if (vector) { // Eigen type is a compile-time vector
168-
if (fixed && size != n)
153+
if (PYBIND11_SILENCE_MSVC_C4127(fixed) && size != n)
169154
return false; // Vector size mismatch
170155
return {rows == 1 ? 1 : n, cols == 1 ? 1 : n, stride};
171156
}
@@ -179,7 +164,7 @@ template <typename Type_> struct EigenProps {
179164
if (cols != n) return false;
180165
return {1, n, stride};
181166
} // Otherwise it's either fully dynamic, or column dynamic; both become a column vector
182-
if (fixed_rows && rows != n) return false;
167+
if (PYBIND11_SILENCE_MSVC_C4127(fixed_rows) && rows != n) return false;
183168
return {n, 1, stride};
184169
}
185170

@@ -596,9 +581,3 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
596581

597582
PYBIND11_NAMESPACE_END(detail)
598583
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
599-
600-
#if defined(__GNUG__) || defined(__clang__)
601-
# pragma GCC diagnostic pop
602-
#elif defined(_MSC_VER)
603-
# pragma warning(pop)
604-
#endif

0 commit comments

Comments
 (0)