Hello people :) My dodgy syntax results in a compiler error. Error message follows, source code shown at the end. Couldn't find any sign of this bug when I searched for it, hopefully that's not because I did a bad search...
g++ test.cpp -o test test.cpp: In instantiation of `Size<1>': test.cpp:34: instantiated from here test.cpp:14: internal compiler error: in lookup_template_function, at cp/pt.c: 4005 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. make: *** [test] Error 1 ---------------8<--------------- #include <iostream> /** SIZE CLASS When lengths are multiplied together, you get areas When area and length are multiplied together, you get volumes Can't add length to an area etc. */ template<int d1> class Size{ friend std::ostream& operator << <>(std::ostream &os,const Size &me); public: Size(double v){ this->v=v; } operator double(){ return v; } Size operator+(const Size& s) const{ return Size<d1>(this->v + s.v); } private: double v; }; std::ostream& operator <<(std::ostream &os,const Size<1>& me){ os<<me.v <<" m"; return os; } std::ostream& operator <<(std::ostream &os,const Size<2>& me){ os<<me.v <<" m²"; return os; } std::ostream& operator <<(std::ostream &os,const Size<3>& me){ os<<me.v <<" m³"; return os; } /* template<int d1,int d2> Size<d1+d2> Size<d1>::operator*(Size<d2> s){ return Size<d1+d2>(this.v * s.v); } */ typedef Size<1> Length; typedef Size<2> Area; typedef Size<3> Volume; using namespace std; int main(void){ Length w=10; cout << "w = " << w << endl; Length d=20; cout << "d = " << d << endl; Area A=w*d; cout << "A = " << A << endl; Length causes_error = A + d; cout << "causes_error = " << causes_error << endl; Length h=5; cout << "h = " << h << endl; Volume V=A*h; cout << "V = " << V << endl; } ----------------------8<-------------------- Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld --with-gnu-as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/sbin --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,f77,pascal,jav a,objc --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --without-included-gettext --enable-interpreter --enable -sjlj-exceptions --disable-version-specific-runtime-libs --enable-shared --disable-win32-registry --enable-java-gc=boehm --disable-has h-synchronization --verbose --target=i686-pc-cygwin --host=i686-pc-cygwin --build=i686-pc-cygwin Thread model: posix gcc version 3.3.1 (cygming special) -- Summary: Internal compiler error in lookup_template_function Product: gcc Version: 3.3.1 Status: UNCONFIRMED Severity: minor Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: john dot pye at student dot unsw dot edu dot au CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18366