Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 162556

Summary: Compiler error when compiling call to templated function within a templated class
Product: Red Hat Enterprise Linux 3 Reporter: Michael Doppler <m.doppler>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0CC: aoliva, jason
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-09-27 09:17:36 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Michael Doppler 2005-07-06 10:14:38 UTC
Description of problem:
The following valid C++ code results in an error message:

class B{
public:
        template <typename T>
        T getValue()
        {
                return T();
        }
};

class A{
public:
        template <typename T>
        void test(){
                B b;
                b.getValue<int>();
        }
};

int main()
{
        A a;
        a.test<int>();
}


Version-Release number of selected component (if applicable):
cpp-3.2.3-52

How reproducible:
Compile the code above.

Steps to Reproduce:
1. Paste the code into test.cpp

2. Call the following command in the directory containing the file: 
g++ -o test test.cpp -lstdc++
  
Actual results:
Error message:
test.cpp: In member function `void A::test()':
test.cpp:15: syntax error before `;' token

Expected results:
Code compiles without an error.

Additional info:
The code compiles fine with g++ 3.4.3-22.1 from RHEL 4.

Comment 2 Alexandre Oliva 2005-09-26 17:35:37 UTC
This is one of those cases in which the C++ grammar is ambiguous, and the parser
in GCC 3.2 wasn't smart enough to tell how to parse the statement because of
limitations in the tools used to create it.  The new parser, introduced in GCC
3.4, was able to overcome this limitation, but it's nearly impossible to
backport the fix.

A syntactic disambiguation, suggested by the standard for situations in which
the postfix-expression before the `.' is template-dependent but accepted in
other cases as well, is to add the `template' keyword before the template-id,
like this:

                b.template getValue<int>();

This code is accepted by GCC 3.2, 3.4, 4.0 and should be accepted by any other
C++ Standard-compliant compilers.

Comment 3 Michael Doppler 2005-09-27 09:17:36 UTC
Thank you for clarifying this issue.

Because resolving the ambiguity works around the problem and a parser backport
is not feasible I set this bug to resolved wontfix.