| 
      
      
      From: Stefan S. <se...@sy...> - 2005-02-25 16:31:57
      
     | 
| Alexander Vodomerov wrote:
> Recently, I've found that OpenC++ (2.8) can not parse following code:
> 
> class X
> {
> public:
>   template <typename T> int g() { return 123; }
> };
> 
> template <typename T> class A
> {
> public:
>   X x;
>   X& getx() { return x; }
>   void f() { getx().g<T>(); }
> };
> 
> int main()
> {
>   A<int> a;
>   a.f();
> }
> 
> It says:
> [alex@lorien ~]$ ./occ -c 1.cpp
> 1.cpp: In member function `void A<T>::f()':
> 1.cpp:12: error: parse error before `;' token
> 
> The 12th line corresponds to getx().g<T>()
> 
> Is this a correct code? I have 4 compilers on my machine (gcc 3.3.5,
> gcc 3.4.3, gcc 4.0.0 snapshot, Intel C/C++ 8.1). All of them
> compile this code cleanly.
The OpenC++ parser is indeed not powerful enough to understand that line.
The reason is that to be able to decide whether '<' is a relational operator
or the start of a template parameter spec, it has to figure out what 'g'
is. That requires symbol lookup, which OpenC++ doesn't do during parsing.
Regards,
		Stefan
 |