This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: c++/570: Internal error 71 with parametrised operator template


The following reply was made to PR c++/570; it has been noted by GNATS.

From: Martin Sebor <sebor@roguewave.com>
To: cschueler@gmx.de
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/570: Internal error 71 with parametrised operator template
Date: Tue, 26 Sep 2000 10:51:06 -0600

 cschueler@gmx.de wrote:
 > 
 ...
 > I tried to implement parametrised operator templates for a vector-math library to have the compiler generate calculations row by row instead of vector by vector, in similarity of "dense arrays".
 > 
 > My intention was, that the code
 > 
 >    Vector3d a, b, c, d;
 >    a = b + c + d;
 > 
 > translates to
 > 
 >    a[0] = b[0] + c[0] + d[0];
 >    a[1] = b[1] + c[1] + d[1];
 >    a[2] = b[2] + c[2] + d[2];
 > 
 > GCC 2.95.2, that is the engine of both DJGPP and MinGW32 that I have on my computer, reports "Internal Error 71" at line 10 of the code listed below:
 > >How-To-Repeat:
 > 
 > template< typename TYPEA, typename TYPEB, const TYPEA &A, const TYPEB &B >
 > struct OP_plus {
 >    float operator[]( int i ) const { return A[i] + B[i]; }
 > };
 > 
 > template< typename TYPEA, typename TYPEB >
 > inline OP_plus< TYPEA, TYPEB, A, B >
                                 ^^^^^
 This is wrong, A and B are not defined.
 
 > operator +( const TYPEA &A, const TYPEB &B )
 > { return OP_plus< TYPEA, TYPEB, A, B >(); }
 > 
 > struct Vector3D
 > {
 >    float x[3];
 >    float operator[]( int i ) const { return x[i]; }
 > 
 >    template< typename TYPE >
 >    Vector3D &operator =( const TYPE &other ) {
 >       x[0] = other[0];
 >       x[1] = other[1];
 >       x[2] = other[2];
 >       return *this;
 >    }
 > };
 > 
 > Vector3D A, B, C, D;
 > 
 > int main()
 > {
 >    A = B + C + D;
 >    return 0;
 > }
 
 Perhaps you meant (this is legal and compiles):
 
 template< typename TYPEA, typename TYPEB>
 struct OP_plus
 {
     const TYPEA &A;
     const TYPEB &B;
     OP_plus (const TYPEA &a, const TYPEB &b): A(a), B (b) { }
     float operator[]( int i ) const { return A[i] + B[i]; }
 };
 
 template< typename TYPEA, typename TYPEB >
 inline OP_plus< TYPEA, TYPEB>
 operator +( const TYPEA &A, const TYPEB &B )
 {
     return OP_plus< TYPEA, TYPEB>(A, B);
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]