This bugzilla service is closed. All entries have been migrated to
Bug 1676 - Template argument deduction: incomplete type ‘Eigen::internal::traits<U>’ used in nested name specifier (C++17)
Summary: Template argument deduction: incomplete type ‘Eigen::internal::traits<U>’ use...
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: unspecified
Hardware: All All
: Normal Compilation Problem
Assignee: Nobody
Depends on:
Reported: 2019-02-06 13:31 UTC by Marc Schmitt
Modified: 2019-12-04 18:27 UTC (History)
4 users (show)


Description Marc Schmitt 2019-02-06 13:31:20 UTC
// Crosspost of:

We encounter an error when serializing an Eigen matrix with boost::serialization.

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:

#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;

// ------------------------------------------

The problem seems to be a bug in GCC (, 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
  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:
Comment 6 Gael Guennebaud 2019-02-07 14:32:04 UTC
While preparing a reduced test case:

I found an easy and general workaround:
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'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:

Note You need to log in before you can comment on or make changes to this bug.