bug report (probably about template instantiation)

Stefan Seefeld seefelds@MAGELLAN.UMontreal.CA
Mon Jan 25 15:07:00 GMT 1999


Hi,

I just found a bug in the following code snippet.

---------------------------------------
#include <iostream>

class A
{
public:
  A() { cout << "A::A" << endl;}
};

template <class T>
class B
{
public:
  B() { cout << "B::B" << endl;}
//   B(const B &) { cout << "B::B(B)" << endl;}
  void operator () (const T &t) {}
private:
  A a;
};

template <class T1, class T2> void C1(T1 &t1, T2 t2) { t2(t1);}
template <class T1, class T2> void C2(T1 &t1, T2 &t2) { t2(t1);}

class D{};

main(int argc, char **argv)
{
  D d;
  B<D> b;     // calls A::A implicitely
  C1(d, b);   // doesn't call A::A (but it should !!!)
  C2(d, b);
}

---------------------------------------

when dropping the copy constructor for B, the A member of B isn't constructed in
the call to C1. (So I can't say whether B is constructed at all in this case)

my compiler gives this info:

Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

Thanks a lot for all the work !!

Stefan

_______________________________________________________              
              
Stefan Seefeld
Departement de Physique
Universite de Montreal
email: seefelds@magellan.umontreal.ca

_______________________________________________________

      ...ich hab' noch einen Koffer in Berlin...



More information about the Gcc-bugs mailing list