GCC may have a defective template parsing routine which seems to mistake the
'<' token in an expression for the beginning of a template argument.  The error
only seems to happen when a templated function evaluates a member of a
templated class or struct with a '<' symbol.

Here is a simple code snippet that reproduces the problem:

template <class T>
struct templated_struct 
{
        int count;
};

template <class T>
int template_func()
{
        templated_struct<T> s;
        if (s.count < 0) return 0;
        return 0;
}

int main()
{
        template_func<int> ();
        return 0;
}

The compiler generates the follow error message when trying to compile the
above code:

test4.cc: In function ‘int template_func()’:
test4.cc:16: error: parse error in template argument list
test4.cc: In function ‘int template_func() [with T = int]’:
test4.cc:22:   instantiated from here
test4.cc:16: error: ‘count’ is not a member template function

Note that the above code compiles just fine if you replace the '<' token in the
IF statement with an '>' or an '==', thus demonstrating that GCC seems to be
confusing the '<' token for a template argument.

A temporary workaround is to put a set of parenthesis around s.count.


-- 
           Summary: Template Parsing Error
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chsalvia at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32409

Reply via email to