c++/5763: Compiler uses the wrong type

jcab@JCABs-Rumblings.com jcab@JCABs-Rumblings.com
Sat Feb 23 17:56:00 GMT 2002

>Number:         5763
>Category:       c++
>Synopsis:       Compiler uses the wrong type
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          mistaken
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 23 17:46:01 PST 2002
>Originator:     Juan Carlos Arevalo-Baeza
>Release:        3.0.3
Compiling the program below, the compiler returns an incorrect error message.

The problem is the type:


When accessed like that, the compiler mistakenly thinks it is:


When, in reality, it is:

filter<phase_2<phase_1> >::iterator<phase_1>

So the code should compile.

I believe the problem might be caused by the typedef on line 15:

typedef filter<phase_2<Phase1> >::iterator<Phase1> iter2;

Where the <Phase1> template argument is incorrectly applied to filter. If I don't use the typedef, the problem doesn't happen. And if I add the required "template" before "iterator" int he typedef, it works as expected.
Compile this little program:

template <  typename GrammarT >
struct filter {
    template < typename T >
    struct iterator
        typedef iterator<T> this_t;

struct phase_1: filter<phase_1> {

template < typename Phase1 >
struct phase_2: filter<phase_2<Phase1> > {
    typedef filter<phase_2<Phase1> >::iterator<Phase1> iter2;

phase_2<phase_1>::iter2::this_t* kk =

What I get is:

$ g++ bug3.cpp -O2 -ftemplate-depth-50 -g
bug3.cpp:22: cannot convert `filter<phase_2<phase_1> >::iterator<phase_1>*' to
   `filter<phase_1>::iterator<phase_1>*' in initialization
The code is incorrect, so fixing the code solves the immediate problem.

Still, the error message received is really misleading, and the original code, where this problem was encountered, compiled without errors but didn't run properly because the wrong types were used.

The code I included here is the smallest I could muster while still showing the type mismatch error.

More information about the Gcc-bugs mailing list