This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[Q] template specializations (ICE)
- To: egcs at cygnus dot com, egcs-bugs at cygnus dot com
- Subject: [Q] template specializations (ICE)
- From: gcl++ Library Development <m dot cvjetko_nO_spaM at rt dot e-technik dot uni-erlangen dot de>
- Date: Tue, 04 May 1999 20:25:12 +0200
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated
- Organization: gcl++ Library Development Uni Erlangen
- Reply-To: m dot cvjetko_nO_spam at rt dot e-technik dot uni-erlangen dot dot de
/*
newsgroups: comp.lang.c++,
comp.lang.c++.moderated,
egcs@cygnus.com, egcs-bugs@cygnus.com
bug-g++@prep.ai.mit.edu
gnu.g++.bug, gnu.g++.help, gnu.g++.lib.bug
comp.std.c++
reply to : vcvjetko@linux.rulz.zg.tel.hr
by removing praising the best OS
[Q] template specializations (ICE)
Hi again!
This time I've tried to do some template specializations and it
works fine for templates with one template parameter, but for
templates with two params I got a little bit confused, moreover
with egcs-1.1.2 I got internal compiler error.
Can You explain me how am I supposed to specialize a class
functions by only one of the template arguments.
Thanx
Miljenko!
*/
#include <iostream>
//#####################################################################
//------------------------------------------------------------
/*
class template with one template parameter!
*/
template <class T >
class X_one
{
public:
void f();
void g();
};
//------------------------------------------------------------
template <class T >
void
X_one<T>::f()
{
g();
cout << " not char and not int!!\n";
return;
};
//...........................................................
template <class T >
void
X_one<T>::g()
{
cout << " for all types the same \n";
return;
};
//------------------------------------------------------------
// Specializations
template <> void X_one<int>::f();
template <> void X_one<char>::f();
//------------------------------------------------------------
template <>
void
X_one<int>::f()
{
g();
cout << " int\n";
return;
};
//...........................................................
template <>
void
X_one<char>::f()
{
g();
cout << " char\n";
return;
};
//#####################################################################
/*
class template with two template parameters!
*/
//------------------------------------------------------------
template <class T1, class T2 >
class X_two
{
public:
void f();
void g();
};
//------------------------------------------------------------
template <class T1, class T2 >
void
X_two<T1,T2>::f()
{
g();
cout << " not char and not int!!\n";
return;
};
//...........................................................
template <class T1, class T2 >
void
X_two<T1,T2>::g()
{
cout << " for all types the same \n";
return;
};
//------------------------------------------------------------
// Specializations
template <class T1> class X_two<T1,int>
{
void f();
};
template <class T1> class X_two<T1,char>
{
void f();
};
template <class T1> void X_two<T1,int>::f();
template <class T1> void X_two<T1,char>::f();
//------------------------------------------------------------
template <class T1>
void
X_two<T1,int>::f()
{
g();
cout << " int\n";
return;
};
//...........................................................
template <class T1>
void
X_two<T1,char>::f()
{
g();
cout << " char\n";
return;
};
//#####################################################################
//------------------------------------------------------------
//------------------------------------------------------------
int main()
{
X_one<int> x_one_i_;
X_one<char> x_one_c_;
X_one<double> x_one_d_;
X_one<long int> x_one_li_;
x_one_i_.f();
x_one_c_.f();
x_one_d_.f();
x_one_li_.f();
X_two<int,int> x_two_i_;
X_two<double,char> x_two_c_;
X_two<long,int,double> x_two_d_;
X_two<double,long int> x_two_li_;
x_two_i_.f();
x_two_c_.f();
x_two_d_.f();
x_two_li_.f();
return 0;
};
/*
gcl@moljac:~/gcl/src/example/Tests/syntax_standard_comformance > g++ -v
template_specialization_one_and_two_paramteters_REPORTED.cpp
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
/usr/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.66/cpp -lang-c++ -v -undef
-D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__
-Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__
-D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix)
-D__EXCEPTIONS -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386
-D__i386 -D__i386__ -Di586 -Dpentium -D__i586 -D__i586__ -D__pentium
-D__pentium__
template_specialization_one_and_two_paramteters_REPORTED.cpp
/tmp/ccuXj0af.ii
GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386
Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++
/usr/local/include
/usr/i586-pc-linux-gnu/include
/usr/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.66/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i586-pc-linux-gnu/egcs-2.91.66/cc1plus
/tmp/ccuXj0af.ii -quiet -dumpbase
template_specialization_one_and_two_paramteters_REPORTED.cc -version -o
/tmp/ccgHYmmo.s
GNU C++ version egcs-2.91.66 19990314 (egcs-1.1.2 release)
(i586-pc-linux-gnu) compiled by GNU C version egcs-2.91.66 19990314
(egcs-1.1.2 release).
template_specialization_one_and_two_paramteters_REPORTED.cpp:141:
Internal compiler error 892.
template_specialization_one_and_two_paramteters_REPORTED.cpp:141: Please
submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
template_specialization_one_and_two_paramteters_REPORTED.cpp:141: See
<URL:http://egcs.cygnus.com/faq.html#bugreport> for details.
*/