Bug report (template specialization)

Alexandre Oliva oliva@dcc.unicamp.br
Fri May 22 04:01:00 GMT 1998


Marco Manfai Yu <yumf@ultimatech.com> writes:

>     I got a "Interal compiler error" compiling the following code
> using egcs-1.0.3a (release version) on Sparc Solaris 2.5.1 and
> Linux.

With the latest snapshot of egcs, this produces:

test.cc:11: template-id `F_Check<D>' in declaration of primary template
test.cc: In function `int main()':
test.cc:20: warning: initialization to `int' from `double'

> I am not very familiar with template specialization syntax but
> I think this should be right.

It is not; there's no such thing as partial specialization of function 
templates, only of class templates.  The best you can do is to
overload the function template:

template <class D, class E> D F_Check(E);
template <class D> D F_Check(D);

Then call, for example,

  int i = F_Check<int>((double)a);

or fully specialize it:

template <class D, class E> D F_Check(E) { ... }
template <> int F_Check<int, int>(int) { ... }

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil




More information about the Gcc-bugs mailing list