c++/3671: g++ incorrectly tries to instantiate multiple member template specializations

Wolfgang Bangerth bangerth@ticam.utexas.edu
Fri Nov 15 19:10:00 GMT 2002


Good question what happens here:
----------------------------------
enum T1 {a};
enum T2 {b};

struct Y {
  template <T1 i> void foo();
  template <T2 i> void foo();
};

template void Y::foo<a> ();

// int main() {
//   Y c;
//   c.foo<a>();
// }
---------------------------------
I get
tmp/g> /home/bangerth/bin/gcc-3.3x-pre/bin/c++ x.cc
x.cc:9: error: cannot convert `T1' to `T2' in initialization
x.cc:9: error: non-constant `<expression error>' cannot be used as template
   argument
x.cc: In instantiation of `void Y::foo() [with T1 i = a]':
x.cc:9:   instantiated from here
x.cc:9: error: explicit instantiation of `void Y::foo() [with T1 i = a]' 
but no
   definition available


If I use the commented main function instead of the explicit 
instantiation, I get
tmp/g> /home/bangerth/bin/gcc-3.3x-pre/bin/c++ x.cc
x.cc: In function `int main()':
x.cc:13: error: cannot convert `T1' to `T2' in initialization
x.cc:13: error: non-constant `<expression error>' cannot be used as template
   argument

which I find even less helpful.

Regards
  Wolfgang

-------------------------------------------------------------------------
Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth




More information about the Gcc-bugs mailing list