This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 1676

Summary: Template argument deduction: incomplete type ‘Eigen::internal::traits<U>’ used in nested name specifier (C++17)
Product: Eigen Reporter: Marc Schmitt <schmitt.marc>
Component: Core - generalAssignee: Nobody <eigen.nobody>
Status: RESOLVED FIXED    
Severity: Compilation Problem CC: chtz, gael.guennebaud, jacob.benoit.1, schmitt.marc
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:

Description Marc Schmitt 2019-02-06 13:31:20 UTC
// 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?
Comment 1 Christoph Hertzberg 2019-02-06 14:58:06 UTC
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.
Comment 2 Gael Guennebaud 2019-02-06 20:06:12 UTC
isn't is a bug in GCC?
Comment 3 Christoph Hertzberg 2019-02-07 10:48:23 UTC
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).
Comment 4 Christoph Hertzberg 2019-02-07 12:15:26 UTC
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 ...
Comment 5 Christoph Hertzberg 2019-02-07 12:33:16 UTC
Also here for future reference:
https://github.com/boostorg/serialization/pull/144
Comment 6 Gael Guennebaud 2019-02-07 14:32:04 UTC
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/
Comment 7 Christoph Hertzberg 2019-02-07 15:18:00 UTC
Much cleaner workaround! I guess this can also be back-ported to 3.3.
Comment 8 Gael Guennebaud 2019-02-07 15:28:30 UTC
done: 4a9887251746
Comment 9 Nobody 2019-12-04 18:27:49 UTC
-- 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.