Bug 48089 - gcc c++ explicit-instatiation template problem
Summary: gcc c++ explicit-instatiation template problem
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 8.0
Hardware: i586
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
Depends On:
TreeView+ depends on / blocked
Reported: 2001-07-09 16:22 UTC by Kenton Varda
Modified: 2007-04-18 16:34 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-01 23:00:00 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Kenton Varda 2001-07-09 16:22:29 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2-2 i686; en-US; 0.7) Gecko/20010316

Description of problem:
See code:

class A
    template<typename T>
    int f()
        return 0;

class B
    A a;
    int g()
        return a.f<int>(); //this works

    template<typename U>
    int h()
        return a.f<int>(); //this doesn't

How reproducible:

Steps to Reproduce:
1.  Compile above code (no special compiler switches necessary).
2.  See error

Actual Results:  testgcctemplatebug.cpp: In method `int B::h ()':
testgcctemplatebug.cpp:23: parse error before `>'

Expected Results:  Code would compile.

Additional info:

If you make A::f into a static function (and call it using "A::f" syntax),
or a global function, it works.  Even stranger, if you make a global
function f which is defined the same as the member function, but you still
call the member function version from B::g, it works.

If you give f an argument of type T*, and you instantiate the template
based on the argument rather than manually specifying the type, that works
too.  For now, I am working around the bug by allowing a dummy template
argument to be used to instatiate the template.

I suppose I am not entirely sure if the above code is valid C++, but the
only other compiler I could test on is MSVC.  Needless to say, it won't
compile the code either.  But that doesn't mean much, now does it?  :)

I am using gcc 2.96-85.

Comment 1 Jakub Jelinek 2001-07-20 13:24:42 UTC
It does not compile with g++ 2.95.2 and g++ 3.0 either.
I don't have ISO C++ standard with me ATM, so I'd suggest you take this
to comp.lang.c++ or something like that.

Comment 2 Kenton Varda 2001-07-25 14:50:33 UTC
Well, I asked on comp.lang.c++, and the two responses I received both said that they 
are pretty sure that is was a compiler bug.  One guy said that he had reported the same 
bug to the GCC 3.0 people and had received no reply.  He also said that Borland C++ 
compiles it just fine.

Comment 3 Richard Henderson 2004-10-01 23:00:00 UTC
Fixed in the gcc 3.4 c++ parser rewrite.

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