partial specialization

Kurt Garloff garloff@student.physik.uni-dortmund.de
Tue Feb 24 10:31:00 GMT 1998


To followup my own message

On Mon, 23 Feb 1998, Kurt Garloff wrote:

> Here are some line of codes, where I try to use partial spezialization but
> the compiler gets an internal compiler error.
> 
> ...
> 
> So, is there anyone able to tell me:
> - if it's a compiler bug (a int.comp.error always somehow is)
> - if my code is correct, and if it's not, what the correct part. spec.
>  syntax is
> - another way of having a templated class and some additional constructors
>  only for certain cases of the template parameters
> 
> ...
> 
> I once tried to DECLARE the extra constructors within the templ. class but
> only to DEFINE them for the cases I want them, but egcs-1.0.x produced
> assembler errors on them and egcs-9802XX didn't accept it at all.
> template <int d, typename T>
> Tensor<2,T>::Tensor (int, int) { ... };

So here's an example with a declaration in the templ. class and
specialized definitions:
/* bug3.cc */
/* Kurt Garloff <garloff@hft.e-technik.uni-dortmund.de> 98/02/24 */

#include <iostream>

template <unsigned dm>
class general
{
 protected:
   unsigned d1, d2;
 public:
   general () : d1 (dm), d2 (0)  {};
   ~general ()  {};
   friend ostream& operator << <> (ostream&, const general<dm>&);
   
   //decls for specialization
   general (unsigned, unsigned);
#ifdef SPEC3
   general (float, unsigned, float);
#endif
};

template <unsigned dm>
ostream& operator << (ostream& os, const general<dm>& g)
{
   return os << g.d1 << " " << g.d2;
};

// partial specialization
template <>
inline general<2>::general<2> (unsigned u0, unsigned u1) : d1(u0)  
{ d2 = u1; };

#ifdef SPEC3
template <>
inline general<3>::general (float u0, unsigned u1, float u2) : d1(u0)  
{ d2 = u1; };
#endif

int main ()
{
   general<1> g1;
   general<2> g2;
   cout << g1 << endl << g2 << endl;
#ifdef SPEC3
   general<3> g3 (1, 2, 3);
#else
   general<2> g3 (1, 2);
#endif
   cout << g3 << endl;
};
     
garloff@student:~/C $ eg++ -g -o bug3 bug3.cc -DSPEC3
bug3.cc:31: `general<2>::general<>(unsigned int, unsigned int)' does not
match any template declaration
bug3.cc:31: confused by earlier errors, bailing out

The strange thing about is, that it compiles and works as expected without
-DSPEC3:

garloff@student:~/C $ eg++ -g -o bug3 bug3.cc
garloff@student:~/C $ bug3
1 0
2 0
1 2

I need any of the two syntaxes to work. Hope somebody can help me with
this or fix the compiler.

Kurt Garloff
<K.Garloff@ping.de>





More information about the Gcc-bugs mailing list