I ran into a strange compile error at the office today and I'm suspecting it to be a bug in our version of GCC (3.4.6). I've been able to boil it down to a few lines of code (below). The compile error I get is:
test.cpp:26: error: expected primary-expression before '>' token
test.cpp:26: error: expected primary-expression before ')' token
The error can be avoided by introducing a temporary variable to store the result of the first statement (bar.value("yoyo")
). Can anyone tell me what causes this? Is it a bug in GCC 3.4.6 (it seems to work in GCC 4.x.x) and are there other similar template-related bugs in this version?
class Foo
{
public:
template<typename T> bool doIt() const { return true; }
};
class Bar
{
public:
Foo value(const char * key)
{
return Foo();
}
};
template<typename T>
void
mytestfunc()
{
Bar bar;
// Works fine:
Foo foo = bar.value("yoyo");
foo.doIt<T>();
// Does not work on gcc 3.4.6:
bar.value("yoyo").doIt<T>();
}
int main(int argc, char * args[])
{
return 0;
}