public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/5763: Compiler uses the wrong type
@ 2002-02-23 17:46 jcab
  0 siblings, 0 replies; only message in thread
From: jcab @ 2002-02-23 17:46 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-02-24  1:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-23 17:46 c++/5763: Compiler uses the wrong type jcab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).