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 - Compiler error when compiling call to templated function within a templated class
Summary: Compiler error when compiling call to templated function within a templated c...
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: gcc
Version: 3.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2005-07-06 10:14 UTC by Michael Doppler
Modified: 2007-11-30 22:07 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-09-27 09:17:36 UTC


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.