http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56760



--- Comment #6 from erik.thi...@thiele-hydraulik.de 2013-03-28 08:27:34 UTC ---

let me paste "v3 source code" that is also added as attachment:





namespace nam { class binbuffer {}; }



template<class T> void func (const T &a, nam::binbuffer &b);



namespace seco {

  template<class X> struct holder { X *fun; };

  template<class T> struct contain { T *wombat; };

}



template<class T> void func(const seco::contain<T> &a, nam::binbuffer &b)

{ func(*a.wombat, b); }



template<class T> void func(const seco::holder<T> &a, nam::binbuffer &b)

{ func(*a.fun, b); }



template<> void func(const int &a, nam::binbuffer &b) {}



int main()

{

  nam::binbuffer b;

  seco::holder<int> foo;

  func(foo, b);

  seco::contain<seco::holder<int> > containHolder;

  func(containHolder, b); // COMMENT THIS OUT AND IT WORKS

  return 0;

}





END OF CODE





when you compile this, it sais



g++ -Wall v3.cpp

/tmp/ccDElJvq.o: In function `void func<seco::holder<int>

>(seco::contain<seco::holder<int> > const&, nam::binbuffer&)':

v3.cpp:(.text._Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE[_Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE]+0x16):

undefined reference to `void func<seco::holder<int> >(seco::holder<int> const&,

nam::binbuffer&)'

collect2: error: ld returned 1 exit status





but when you comment out the line "COMMENT THIS OUT AND IT WORKS" then it

compiles.



now consider the line "func(foo, b)". here exactly the function gets called

that the linker sais is not defined. How can the linker say the function is not

defined, even though it obviously is defined?



you can make it even more clear: comment out this:



//template<class T> void func(const seco::holder<T> &a, nam::binbuffer &b)

//{ func(*a.fun, b); }



but reenable the line "COMMENT THIS OUT AND IT WORKS"



then you get this output:



g++ -Wall v3.cpp

/tmp/cc3keqh3.o: In function `main':

v3.cpp:(.text+0x1e): undefined reference to `void func<seco::holder<int>

>(seco::holder<int> const&, nam::binbuffer&)'

/tmp/cc3keqh3.o: In function `void func<seco::holder<int>

>(seco::contain<seco::holder<int> > const&, nam::binbuffer&)':

v3.cpp:(.text._Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE[_Z4funcIN4seco6holderIiEEEvRKNS0_7containIT_EERN3nam9binbufferE]+0x16):

undefined reference to `void func<seco::holder<int> >(seco::holder<int> const&,

nam::binbuffer&)'

collect2: error: ld returned 1 exit status



you see, it sais two times that the function is not defined. that's OK! now if

you reenable:



template<class T> void func(const seco::holder<T> &a, nam::binbuffer &b)

{ func(*a.fun, b); }



then only the second error message keeps being there. but it misses exactly the

same function!



what's going on here? the function is there and it gets called once. why cannot

it get called twice???

Reply via email to