This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
invoking a template method parsing bug
- From: David Durham <david dot durham at wcom dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 14 Jan 2002 18:14:19 -0600
- Subject: invoking a template method parsing bug
Here is a bug in gcc (2.96) which I could find several people asking
about but never could find a reponse to... So here goes my workaround to
fix the problem...
In the following code:
struct A
{
template<class T1> void f() {}
};
template<class T2> struct B
{
void g()
{
A a;
a.f<int>(); // (11) DOES NOT WORK
((A)a).f<int>(); // (12) DOES WORK
}
};
you get a parse error:
> gcc -c file.cpp
file.cpp: In method `void B<T2>::g ()':
file.cpp:11: parse error before `>'
...
I believe the problem is caused by gcc attempting to get some kind of
information about the type of 'a' before continuing parsing the
'.f<int>();'
So if you cast 'a' to its type it works... I also tried static_cast
and dynamic_cast instead of the old 'C' style cast and they too work.
If it's not a type thing, it's gotta just be something about the
syntax that's getting thrown off unless you put something else there to
change the parsing path... But if that were true, I would expect just (
)'s around 'a' would have worked, which they don't.. Nor does taking the
address of 'a' and using '->'...
I haven't tried gcc 3.0, but I hope its fixed there...
Anyway, I thought I'd post what I found since I couldn't find any help
from others...
-- Davy