This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/5763: Compiler uses the wrong type



>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
>Closed-Date:
>Last-Modified:
>Originator:     Juan Carlos Arevalo-Baeza
>Release:        3.0.3
>Organization:
>Environment:
CygWin
>Description:
Compiling the program below, the compiler returns an incorrect error message.

The problem is the type:

phase_2<phase_1>::iter2::this_t

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

filter<phase_1>::iterator<phase_1>

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.
>How-To-Repeat:
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 =
    reinterpret_cast<
        phase_2<phase_1>::iterator<phase_1>*
    >
    (0);
---

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
---
>Fix:
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.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]