This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: internal error: template member template


Maybe my previous code is not valid, but I run into some crazy error messages
when changing :-(

First: This code fragment compiles fine:
-----------------------------------------------------
#include <iostream>

template<int m> void f1(){ cerr << m << endl;}

template<int m> class f2 {
public:
  static inline void Exec() { f1<m>(); }
};

template<int i, template<int> class f> void ff() {  f<i>::Exec(); }

int main() {  ff<5,f2>();  return(0);}
-----------------------------------------------------

Now if I would like to omit the template arguments of f, e.g.

template<int i, template<> class f> void ff() {  f<i>::Exec(); }

I get an internal compiler error.
But maybe ANSI forbids such stuff - one day the compiler will catch such
a garbage :-)

So I inserted argument "int" into the example of my previous message
and modified the call inserting keyword template
ending up with a file that compiles fine, but does not create the
expected loop: (a correct running version without member templates is attached
but I wanted this special calling syntax)

Please take a look at it.
------------------------------------------------------
#include <iostream>

template<int m> void f1(){ cerr << m << endl;}

template<int m> class f2 {
public:
  static inline void Exec() { f1<m>(); }
};


template<int i, template<int> class f> void ff() {
  f<i>::Exec();
}

template <int i, int j, bool b=(i<=j)>
class LoopFromTo {
public:
  template<template<int> class f> static void Exec() {
    cerr << "You are wrong here" << endl;
  }
};

template <int i, int j>
class LoopFromTo<i, j, true> {
public:
  template<template<int> class f> static void Exec() {
    f<i>::Exec();

    // *******************************************************************
    // here is a problem: next line leads to nothing             !!!!!!!!!
    // no warnings, no error messages ... no execution :-(       !!!!!!!!!
    LoopFromTo<i+1, j>::template Exec<f>(); // is this here forbidden?
    // *******************************************************************
  }
};

template <int i, int j>
class LoopFromTo<i, j, false> {
public:
  template<template<int> class f> static void Exec() { }
};


int main() {
  LoopFromTo<1,4>::template Exec<f2>();
  cerr << endl;

  ff<5,f2>();

  return(0);
}
-----------------------------------------------------------


#include <iostream>

template<int m> void f1(){ cerr << m << endl;}

template<int m> class f2 {
public:
  static void Exec() { f1<m>(); }
};


template <int i, int j, template<int> class f, bool b=(i<=j)> 
class LoopFromTo {
public:
  static void Exec() { cerr << "You are wrong here" << endl; }
};

template <int i, int j, template<int> class f> 
class LoopFromTo<i, j, f, true> {
public:
  static void Exec() {
    f<i>::Exec();
    LoopFromTo<i+1,j,f>::Exec();
  }
};

template <int i, int j, template<int> class f> 
class LoopFromTo<i, j, f, false> {
public:
  static void Exec() {}
};


int main() {
  LoopFromTo<1,4,f2>::Exec();
  LoopFromTo<4,4,f2>::Exec();
  LoopFromTo<5,4,f2>::Exec();

  return(0);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]