Skip to content

Commit 3793c7e

Browse files
jagermanwjakob
authored andcommitted
Silence new MSVC C++17 deprecation warnings
In the latest MSVC in C++17 mode including Eigen causes warnings: warning C4996: 'std::unary_negate<_Fn>': warning STL4008: std::not1(), std::not2(), std::unary_negate, and std::binary_negate are deprecated in C++17. They are superseded by std::not_fn(). You can define _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING or _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have received this warning. This disables 4996 for the Eigen includes. Catch generates a similar warning for std::uncaught_exception, so disable the warning there, too. In both cases this is temporary; we can (and should) remove the warnings disabling once new upstream versions of Eigen and Catch are available that address the warning. (The Catch one, in particular, looks to be fixed in upstream master, so will probably be fixed in the next (2.0.2) release).
1 parent 7ab1cd3 commit 3793c7e

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

include/pybind11/eigen.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
# endif
2323
#endif
2424

25-
#include <Eigen/Core>
26-
#include <Eigen/SparseCore>
27-
2825
#if defined(_MSC_VER)
2926
# pragma warning(push)
3027
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
28+
# pragma warning(disable: 4996) // warning C4996: std::unary_negate is deprecated in C++17
3129
#endif
3230

31+
#include <Eigen/Core>
32+
#include <Eigen/SparseCore>
33+
3334
// Eigen prior to 3.2.7 doesn't have proper move constructors--but worse, some classes get implicit
3435
// move constructors that break things. We could detect this an explicitly copy, but an extra copy
3536
// of matrices seems highly undesirable.

tests/test_eigen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include "constructor_stats.h"
1212
#include <pybind11/eigen.h>
1313
#include <pybind11/stl.h>
14+
15+
#if defined(_MSC_VER)
16+
# pragma warning(disable: 4996) // C4996: std::unary_negation is deprecated
17+
#endif
18+
1419
#include <Eigen/Cholesky>
1520

1621
using MatrixXdR = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;

tests/test_embed/catch.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
#include <pybind11/embed.h>
55

6+
#ifdef _MSC_VER
7+
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to catch
8+
// 2.0.1; this should be fixed in the next catch release after 2.0.1).
9+
# pragma warning(disable: 4996)
10+
#endif
11+
612
#define CATCH_CONFIG_RUNNER
713
#include <catch.hpp>
814

tests/test_embed/test_interpreter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#include <pybind11/embed.h>
2+
3+
#ifdef _MSC_VER
4+
// Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to catch
5+
// 2.0.1; this should be fixed in the next catch release after 2.0.1).
6+
# pragma warning(disable: 4996)
7+
#endif
8+
29
#include <catch.hpp>
310

411
#include <thread>

0 commit comments

Comments
 (0)