Is this a template bug in gcc-2.95.1 ?

Wolfgang Glas Wolfgang.Glas@hfm.tu-graz.ac.at
Tue Aug 31 00:40:00 GMT 1999


Hi there,

  I have just been creating another template+friend example which seems to evoke
erroneous behaviour of g++-2.95.1 in my eyes.

Please don't think that this example is exotic. I used to implement fuzzy
numbers, where I coded the alpha-levels by using a third template argument that
points to an array.

  But let's go on to my source. It fails to compile with g++-2.95.1 but compile
with egcs-1.1.2
  
------------file: templ_bug.cc----------------------------------------------
#ifdef MORE_COMPLEXITY
#define TMPL_ARG3(a) ,a
#else
#define TMPL_ARG3(a)
#endif

template <class T, unsigned n TMPL_ARG3(const T *ref)>
class vec
{
  T v[n];
 public:
  vec () { for (unsigned i=0;i<n;i++) v[i]=0; }
  vec (const T& x) { for (unsigned i=0;i<n;i++) v[i]=x; }

  template <class U, unsigned m TMPL_ARG3(const U *rref)> 
  friend vec<U,m TMPL_ARG3(rref)> 
  operator+ (U a, const vec<U,m TMPL_ARG3(rref)> &b);  
};

template <class T, unsigned n TMPL_ARG3(const T *ref)>
inline vec<T,n TMPL_ARG3(ref)>
operator+ (T a, const vec<T,n TMPL_ARG3(ref)> &b)
{ 
  vec<T,n TMPL_ARG3(ref)>  ret;
  for (unsigned i=0;i<n;i++) ret.v[i] = a + b.v[i]; 
  return ret;
}

extern const int i_ref;
const int i_ref = 1;

// expl instantiation.
template class vec<int,3 TMPL_ARG3(&i_ref)>;

int main()
{
  vec<int,3 TMPL_ARG3(&i_ref)> a(2);
  
  3+a;
}
------------end of file: templ_bug.cc---------------------------------------

  Unfortunately it's not easy to read, but teh basic thing is that I bring in a
third template argmuent by using a define...

---------compile session------------
/home/wglas/CC/this_and_that > g++ -v
Reading specs from /usr/local/lib/gcc-lib/mips-sgi-irix6.5/2.95.1/specs
gcc version 2.95.1 19990816 (release)
/home/wglas/CC/this_and_that > g++ -c templ_bug.cc
/home/wglas/CC/this_and_that > g++ -DMORE_COMPLEXITY -c templ_bug.cc
templ_bug.cc: In function `int main()':
templ_bug.cc:39: no match for `int + vec<int,3,&i_ref> &'
/home/wglas/CC/this_and_that > g++ -Vegcs-2.91.66 -c templ_bug.cc
/home/wglas/CC/this_and_that > g++ -Vegcs-2.91.66 -DMORE_COMPLEXITY -c
templ_bug.cc
------end of compile session--------

 So, if I introduce the third arg, gcc-2.95.1 complains, while egcs-1.1.2 does
the job.

 Thanks for the patience to read all my bug reports. Your efforts could help me
a lot because I have Ziliions of line of template code, which I have to
rearrange for gcc-2.95 if this turns out to be a bug.

  Reagrds,

    Wolfgang

--
Mag. Wolfgang Glas
Institut fuer hydraulische Stroemungsmaschinen
Kopernikusgasse 24                              Phone:++43/316/873/7578
A-8010 Graz                                     Fax:  ++43/316/873/7577

mailto:Wolfgang.Glas@hfm.tu-graz.ac.at   
http://fhysmsg01.tu-graz.ac.at/Wolfgang.Glas/


More information about the Gcc-bugs mailing list