// Crosspost of: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84075 We encounter an error when serializing an Eigen matrix with boost::serialization. See: https://stackoverflow.com/questions/54534047/eigen-matrix-boostserialization-c17 The problem seems to be connected with the (changed? new?) template argument deduction for C++17 starting from GCC7.1 The same code compiles successfully with clang and GCC6 (regardless of the C++ version) or in c++14 mode A simplified test-case (without boost): // ------------------------------------------ // test-case (see: https://stackoverflow.com/a/54536756/1267320) #include <Eigen/Core> template<template<class U>class SPT>void f(SPT<class U>&); template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> void f(Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & arMatrix){} int main() { Eigen::Matrix2d m; f(m); } // ------------------------------------------ The problem seems to be a bug in GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84075), but maybe Eigen should/could provide a workaround for GCC in C++17 mode?
Actually, we could insert this somewhere (probably guarded by some #if GCC>=6 guard): namespace boost { namespace serialization { struct U; // forward-declaration for Bug 1676 } } // boost::serialization namespace Eigen { namespace internal { // Workaround for bug 1676 template<> struct traits<boost::serialization::U> {enum {Flags=0};}; } } But this looks like an ugly hack for a very specific problem. I guess this would be justifiable, if we provided an Eigen-boost-serialization module ourself. I'll post this as a different workaround at the SO-post for now.
isn't is a bug in GCC?
Yes that is very likely a bug in gcc (unless there is some weird wording in the standard which nobody except gcc interprets correctly *g*). This would be a workaround for that bug. As I said, I'm not really in favor of that, either. But this bug effects lots of gcc users. On the other hand, the workaround is very easy to apply by users themselves (in case they actually use boost-serialization and use it as in the original SO-question ...) So, currently I'm tending to WONTFIX -- *maybe* add it to some FAQ (but the SO post will likely be google-able, if other users hit the same problem).
Actually, I also works, if the forward declaration in boost/serialization/shared_ptr_helper.hpp: template<class Archive, template<class U> class SPT > void load( Archive & ar, SPT< class U > &t, const unsigned int file_version ); Gets replaced by a more meaningful: template<class Archive, template<class> class SPT, class U > void load( Archive & ar, SPT< U > &t, const unsigned int file_version ); Definitely not an issue which Eigen should solve ...
Also here for future reference: https://github.com/boostorg/serialization/pull/144
While preparing a reduced test case: https://godbolt.org/z/uIy1Uu I found an easy and general workaround: https://bitbucket.org/eigen/eigen/commits/28ca6976ccea/
Much cleaner workaround! I guess this can also be back-ported to 3.3.
done: 4a9887251746
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1676.