internal error with -g
Stefan Schwarzer
sts@ica1.uni-stuttgart.de
Sat Mar 21 14:16:00 GMT 1998
//
// Hi!
//
// The following code compiles fine WITHOUT THE -g FLAG.
// WITH THE -g FLAG, an internal compiler error is generated
//
// This error disappears, when
// (i) either the ctor in the specialization is not a template member
// (ii) the copy ctor in the specialization is commented out
//
// Best regards and hope that helps.
//
// gcc -v
// Reading specs from /local/gcc-2.8.1/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.1/specs
// gcc version 2.8.1
//
// Not surprisingly, the egcs-1.0 has the same problem:
//
// gcc -v
// Reading specs from /local/egcs-1.0/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.21/specs
// gcc version egcs-2.90.21 971202 (egcs-1.00 release)
//
//
/////////////////////////////////////////////////////////////////////////
class XTVec{
protected:
int x[3];
public:
XTVec(){x[0]=x[1]=x[2]=0;};
XTVec(int ax,int y=0,int z=0){x[0]=ax;x[1]=y;x[2]=z;};
const int& operator[](int i) const { return x[i]; }
};
//: Array type, implementation as array of arrays
template < class T, int NDIM >
struct PTS_RArray {
// need this to remove the confusion of new in the constructor about (type *)
typedef PTS_RArray<T,NDIM-1> * ArrPtr;
typedef PTS_RArray<T,NDIM-1> Arr;
// no default constructor, need to specify limits!
PTS_RArray( const XTVec &a_first, const XTVec &a_lastpp, int dim=0):
m_begin(a_first[dim]),
m_end (a_lastpp[dim])
{
a = new ArrPtr[m_end-m_begin];
// uninitialized pointers to the lower dimensional constituents
a -= m_begin;
// allocate the lower dimensional array components
for( int i=m_begin; i < m_end; i++ )
a[i] = new Arr(a_first, a_lastpp, dim+1);
}
~PTS_RArray()
{
// get rid of the 'single' components
for( int i=m_begin; i < m_end; i++ ) delete a[i];
// and of their 'container'
a += m_begin;
delete a;
}
PTS_RArray<T,NDIM-1> &operator[](int i){
return (*a[i]);
}
private:
PTS_RArray<T,NDIM-1> **a;
int m_begin, m_end;
};
template <class T>
struct PTS_RArray<T,1>
{
// ########################## the culprit #####################
template<class VEC>
PTS_RArray(const VEC &a_first, const VEC &a_lastpp, int dim=0):
m_begin(a_first[dim]), m_end(a_lastpp[dim])
{
a = new T[m_end-m_begin];
a -= m_begin;
}
~PTS_RArray()
{ a += m_begin;
delete a;
}
T&
operator[](int i) {
return a[i];
}
// ########################## the culprit #####################
PTS_RArray(const PTS_RArray &rhs){
*this = rhs;
}
PTS_RArray &
operator=(const PTS_RArray &rhs){
for (int i=m_begin; i<m_end; i++)
a[i] = rhs[i];
return *this;
}
private:
int m_begin, m_end;
T *a;
};
main()
{
XTVec b(0,0,0), e(10,10,10);
PTS_RArray<double,1> c(b,e);
for( int i=0; i<10; i++ )
c[i] = i + 1;
}
More information about the Gcc-bugs
mailing list