Bug 35008 - [4.2 Regression] Bug in processing nested typedef in nested template class in method definition
Summary: [4.2 Regression] Bug in processing nested typedef in nested template class in...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.1
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 35016 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-01-29 02:35 UTC by Wirawan Purwanto
Modified: 2009-03-31 15:04 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 4.1.1 4.3.0
Known to fail: 4.1.2 4.2.5
Last reconfirmed: 2008-01-29 15:32:29


Attachments
Sample code to cause compilation error. (740 bytes, text/plain)
2008-01-29 15:00 UTC, Wirawan Purwanto
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wirawan Purwanto 2008-01-29 02:35:09 UTC
The following testcase fails to compile: 

template <typename data1> struct outer1
{
    typedef int my_value_type;  // define a nested datatype

    template <typename servert> struct inner1
    {
        typedef outer1<data1> myboss;
// borrow the boss's datatype << -- don't reduce or change this one:
        typedef typename myboss::my_value_type my_value_type;
        my_value_type return_x();
    };

};

// g++ 4 choked on this one:
template <typename data1>
template <typename servert>
typename outer1<data1>::template inner1<servert>::my_value_type
outer1<data1>::inner1<servert>::return_x()
{
    return 4;
}

void testme()
{
    outer1<float>::inner1<int> Inner1;
    int rslt = Inner1.return_x(); // to instantiate and cause error
}


It is basically like this:
* outer1 class template has a nested datatype called "my_value_type"
* inner1 borrows the "my_value_type" from outer1 (its parent)

Then when we want to instantiate return_x() above, g++ gives the following error:

template-typename4.cpp:19: error: prototype for ‘typename outer1<data1>::inner1<servert>::my_value_type outer1<data1>::inner1<servert>::return_x()’ does not match any in class ‘outer1<data1>::inner1<servert>’
template-typename4.cpp:10: error: candidate is: typename outer1<data1>::my_value_type outer1<data1>::inner1<servert>::return_x()
template-typename4.cpp:19: error: template definition of non-template ‘typename outer1<data1>::inner1<servert>::my_value_type outer1<data1>::inner1<servert>::return_x()’

I can work around this by changing line 18 above:

  typename outer1<data1>::template inner1<servert>::my_value_type

to

  typename outer1<data1>::my_value_type

then it would compile. But I think this is a bug. It used to compile with g++ 3. Other compilers such as Intel C++ (version 9.1), PGI C++ 7 all accept this language construct.
Comment 1 Richard Biener 2008-01-29 13:06:34 UTC
The first snippet works for me, the second says

t.C:3: error: expected nested-name-specifier before 'outer1'
t.C:3: error: too many template-parameter-lists
t.C: In function 'void testme()':
t.C:11: error: 'outer1' was not declared in this scope
t.C:11: error: expected primary-expression before 'float'
t.C:11: error: expected `;' before 'float'
t.C:12: error: 'Inner1' was not declared in this scope

so - what is the testcase that you are looking at?
Comment 2 Wirawan Purwanto 2008-01-29 14:59:17 UTC
The whole snippet must be included the (un)desirable error to show up. Let me give an attachment to make it clear.
Comment 3 Wirawan Purwanto 2008-01-29 15:00:40 UTC
Created attachment 15047 [details]
Sample code to cause compilation error.
Comment 4 Richard Biener 2008-01-29 15:25:13 UTC
*** Bug 35016 has been marked as a duplicate of this bug. ***
Comment 5 Richard Biener 2008-01-29 15:32:29 UTC
I believe we have a dup for this somewhere.  Broken on the 4.1 and 4.2 branch.
Comment 6 Joseph S. Myers 2009-03-31 15:04:43 UTC
Closing 4.2 branch, fixed in 4.3.