971201-g++ parse error (with member templates)
Mark Mitchell
mmitchell@usa.net
Sat Dec 6 18:36:00 GMT 1997
>>>>> "Dirk" == Dirk Herrmann <dirk@ida.ing.tu-bs.de> writes:
Dirk> Hello everybody!
Dirk> The following code gives a parse error:
>> cat test.cc
Dirk> struct X { template <class Y> Y& f(); };
Dirk> int main(int, char**) { X x; int i = x.f<int>(); }
>> g++ test.cc
Dirk> test.cc: In function `int main(int, char **)': test.cc:9:
Dirk> parse error before `>'
That's because you have to say:
int i = x.template f<int>();
This is the usage mandated in the standard. I agree that the error
message could be more helpful.
Dirk> Nevertheless, changing the line 9 to int i = x.f(); and
Dirk> compiling again correctly gives:
>> g++ test.cc
Dirk> test.cc: In function `int main(int, char **)': test.cc:9:
Dirk> incomplete type unification test.cc:9: no matching function
Dirk> for call to `X::f ()'
That's because there's no way here to know what version of f() you
want. This, too is correct behavior.
Dirk> Best regards, Dirk Herrmann
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
More information about the Gcc-bugs
mailing list