This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
partial specialization
- To: egcs-bugs at cygnus dot com
- Subject: partial specialization
- From: Kurt Garloff <garloff at student dot physik dot uni-dortmund dot de>
- Date: Mon, 23 Feb 1998 18:57:57 +0100 (MET)
Hi,
Here are some line of codes, where I try to use partial spezialization but
the compiler gets an internal compiler error.
/* bug2.cc */
/* Kurt Garloff <garloff@hft.e-technik.uni-dortmund.de> 98/02/23 */
#include <iostream>
template <unsigned dim>
class general
{
protected:
unsigned d1, d2;
public:
general () : d1 (dim), d2 (0) {};
friend ostream& operator << <> (ostream&, const general<dim>&);
};
template <unsigned dim>
ostream& operator << (ostream& os, const general<dim>& g)
{
return os << g.d1 << " " << g.d2;
};
// partial specialization
template <unsigned dim>
class general<2> : public general<dim>
{
public:
general (unsigned u0, unsigned u1) { d1 = u0; d2 = u1; };
//friend ostream& operator << <> (ostream&, const general<2>&);
};
int main ()
{
general<1> g1;
general<2> g2;
cout << g1 << endl << g2 << endl;
};
garloff@student:~/C $ egcc -v
Reading specs from
/usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.08/specs
gcc version egcs-2.91.08 980214 (gcc-2.8.0 release)
garloff@student:~/C $ eg++ -g -o bug2 bug2.cc
bug2.cc: In function `int main()':
bug2.cc:34: Internal compiler error.
bug2.cc:34: Please submit a full bug report to `egcs-bugs@cygnus.com'.
garloff@student:~/C $ eg++ -o bug2 bug2.cc
bug2.cc: In function `class ostream & operator <<<2>(class ostream &,
const class general<2> &)':
bug2.cc:19: member `d2' is protected
bug2.cc:19: member `d1' is protected
If I uncomment l. 28, the compiler also gets an internal compiler error
without -g. I have another program, where I get the i.c. error with -g,
but I'm able to compile without, but the default constructor for the
specialized class isn't called at all then (which results in a segfaulting
program) !
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
If anybody's interested: The idea is to have a general
template<int d,typename T> Tensor {..}; class, with a general constructor
Tensor<int,T> (Vector<int>&), Vector containing the numbers of elements in
every direction and to have special constructors for rank = 1, 2, 3:
Tensor<1,T> (int); Tensor<2,T> (int,int); Tensor<3,T> (int,int,int);
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) { ... };
Regards,
Kurt Garloff
<garloff@hft.e-technik.uni-dortmund.de>