The following code: ----------------------bug.cc ---------------------------- template< unsigned int flavor > class A { public: template<unsigned int _flavor> A<_flavor>& change_flavor() { typedef A<_flavor> new_flavor; return reinterpret_cast< new_flavor& >( *this ); }; }; // this one compiles int kungfoo() { A<1> test; A<2> test2( test.change_flavor<2>() ); return 1; } #if 1 // this one not template<int k> int kungfoo_template() { A<1> test; A<2> test2( test.change_flavor<2>() ); return k; } #endif int main() { return kungfoo(); // return kungfoo_template<1>(); } ------------------------- end bug.cc ---------------------- produces: ---- cptchaos@motion debug_g++ $ g++ bug.cc -o bug bug.cc: In function `int kungfoo_template()': bug.cc:31: syntax error before `)' token ---- with: ---- cptchaos@motion debug_g++ $ g++ --version g++ (GCC) 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, propolice) Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ---- if you change the #if 1 to #if 0 the file will compile. Because off the fact, that the not templated function uses exact the same syntax like the templatet one, I assume that the systax errror is a false positive, that prohibits compiling valid code. I could reproduce the error with g++-2.95 and g++-3.3 on my debian system: --- station% gcc-2.95 bug.cc bug.cc: In function `int kungfoo_template()': bug.cc:31: parse error before `(' station% gcc-2.95 --version 2.95.4 station% gcc-3.3 bug.cc bug.cc: In function `int kungfoo_template()': bug.cc:31: error: parse error before `)' token station% gcc-3.3 --version gcc-3.3 (GCC) 3.3 (Debian) Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --- PS: I need this reinterpret_cast tric for some aggressive compile_time optimisations, and I now what I am doing there, and it makes sense.
This is a known bug. It is already fixed in development sources of gcc and will be fixed in 3.4. For the time being, you can work around the problem by writing A<2> test2( test.template change_flavor<2>() ); or A<2> test2( test.A<1>::change_flavor<2>() ); Regards Wolfgang
Reopen all these, because they are duplicates...
...of PR 795. *** This bug has been marked as a duplicate of 795 ***