Eigen & GCC 5 : class std::binder2nd is deprecated

4.5k Views Asked by At

I just restarted working on a project which has been on hold for a few months. Last time I compiled it it was working just fine, without any error nor warning. Yet when I tried to compile it earlier today I got this warning

attention : ‘template<class _Operation> class std::binder2nd’ is deprecated [-Wdeprecated-declarations]

This warning literally appears hundreds of time when including Eigen/Geometry, which I use all over my project

In file included from [...]/include/Eigen/src/Core/ArrayBase.h:109:0,
                 from [...]/include/Eigen/Core:350,
                 from [...]/include/Eigen/Geometry:4,
                 from [...]/include/[myproject]/types.hh:8,
                 from [...]/include/[myproject]/voronoi.hh:8

Since then I haven't updated Eigen (is used 3.2.4 which is still the last update today). However, since last time I compiled it, GCC has been updated to 5.1.0 (I'm using archlinux)

Question:

  • Is there an issue with gcc 5.1.0 telling me std::binder2nd is deprecated
  • Should Eigen be updated ?
  • How can I silent those specific warning without loosing the verbosity of my build ?

ANSWER

I appreas that std::bind2nd is really deprecated and that a commit has been done to solve that in Eigen. This commit is however not yet merged with the master branch :/ (and doesn't solve the issue as some std::bind2nd are still present in Eigen's code)

Bottom line is: Eigen's last stable version is deprecated

3

There are 3 best solutions below

4
Jonathan Wakely On BEST ANSWER
  • Is there an issue with gcc 5.1.0 telling me std::binder2nd is deprecated

No, the C++ standard says it's deprecated in C++11, so if you compile in C++11 mode then it is supposed to be deprecated.

  • Should Eigen be updated ?

Yes. if it wants to be C++17 compatible, as std::bind2nd doesn't exist post-C++14 at all.

  • How can I silent those specific warning without loosing the verbosity of my build ?

Suppress the warning. Either compile with -Wno-deprecated-declarations on the command-line or do it in the source when including the Eigen headers:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <eigen/whatever.h>
#pragma GCC diagnostic pop

Or, as the other answer says, tell GCC to treat the Eigen headers as system headers, which happens automatically if they are in /usr/include, or are included with -isystem, or are included from another header that does:

#pragma GCC system_header
#include <eigen/whatever.h>
4
Jake On

Instead of using the -I flag to include files use -isystem to include Eigen headers:

g++-5 -isystem/usr/include/eigen3 source_file_here.cpp

This flag is intended for system headers that don't conform to C standards but are considered false positives when warnings are generated. Eigen headers are used much like system headers and thus for most users the warnings are not helpful but merely an annoying false positive.

Credit goes to Ilya Popov's comment in the original question.

0
Vignesh On

How can I silent those specific warning without loosing the verbosity ?

Edit the CMakeLists.txt file. Add this line somewhere after CMAKE_CXX_FLAGS is set.

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")

Previous answer mentioned adding this to #pragma or to command line. I am biased against #pragma because I find it hard later on to remember where I put it. So as general practice, I try to avoid #pragma. Adding to command line means you have to remember to type this everytime you recompile.