Using declarations in a template of a derived class not recognized by g ++

The following code cannot compile with g ++ 4.9, 5.4, and 6.2.

template <class T, int M, int N>
struct Matrix { };

template <typename T> struct Traits;
class Derived;

template <>
struct Traits<Derived>
{
  static constexpr int N= 3;
};

template <typename T>
class Base: public Traits<T>
{
protected:
  using Traits<T>::N;
  static const Matrix<double,N,N> Mat;
};

template <typename T>
const Matrix<double,Base<T>::N,Base<T>::N> Base<T>::Mat;

class Derived: public Base<Derived> {};

int main()
{
Derived foo;
}

I get an error message ‘const Matrix<double, #‘using_decl’ not supported by dump_expr#<expression error>, #‘using_decl’ not supported by dump_expr#<expression error>, (AutoAlign | (((#‘using_decl’ not supported by dump_expr#<expression error> == 1) && (#‘using_decl’ not supported by dump_expr#<expression error> != 1)) ? RowMajor : (((#‘using_decl’ not supported by dump_expr#<expression error> == 1) && (#‘using_decl’ not supported by dump_expr#<expression error> != 1)) ? ColMajor : ColMajor))), #‘using_decl’ not supported by dump_expr#<expression error>, #‘using_decl’ not supported by dump_expr#<expression error> > Base<T>::Mat.

I do not understand what is wrong. Can anyone help?

The workaround consists of:

template <typename T>
class Base: public Traits<T>
{
protected:
  static constexpr auto N= Traits<T>::N;
  static const Matrix<double,N,N> Mat;
};
+4
source share

Source: https://habr.com/ru/post/1658084/


All Articles