Topic: Private type visibility need? (Bug w BCC 4.0 and gcc 2.5.8)


Author: heinz@hwg.muc.de (Heinz Wrobel)
Date: Sun, 30 Jan 94 10:32:04 GMT
Raw View
Jyrki Tuomi (jjt@cs.uta.fi) wrote:
: Is anyone able to try this out with other C++ compilers?  What do they say?

Comeau C++ 3.0 (C) Copyright 1988-1991 AT&T, Comeau Computing

(a cfront port)

works.

: Jyrki Tuomi                    |  "The only bright side to this [global envi-
:          jjt@cs.uta.fi         |  ronment pollution] is that eventually there

--
Heinz Wrobel        Edotronik GmbH: heinz@edohwg.adsp.sub.org
                    Private Mail:   heinz@hwg.muc.de
My private FAX: +49 89 850 51 25, I prefer email




Author: peters@phibm60c.Physik.Uni-Augsburg.DE (Peter Schmitteckert (Tel. 5977-246))
Date: Sun, 30 Jan 1994 20:03:55 GMT
Raw View
In article <2ibcj8$8o2@vuokko.uta.fi>, jjt@cs.uta.fi (Jyrki Tuomi) writes:
...
|> Is anyone able to try this out with other C++ compilers?  What do they say?

On a RS6000 AIX3.2.4 using xlC it works.

Bye Peter




Author: jjt@cs.uta.fi (Jyrki Tuomi)
Date: 28 Jan 1994 15:56:24 GMT
Raw View
The following short program demonstrates a bug (?) which some C++ compilers
seem to have with member function argument type matching when argument type
is a private one.  I places a question-mark after the word 'bug' because I
couldn't find a definite answer from the ARM.  It sure does look like a bug
to me.  If somebody *knows* what the right behaviour for a C++ compiler is
while processing the file below, I'd be glad to be educated about this.

The following compilers compile (and run) this program without complaint:
    - Centerline ObjectCenter 2.0
    - Symantec C++ 6.1

The following compilers fail to compile this program:
    - Borland C++ 3.1 (appears to be very confused at line 52)
    - Borland C++ 4.0 (appears to be slightly less confused at
                       non-existent line 71, Windows IDE also messes up
                       the source file window right after compiling)
    - GNU C++ 2.5.8 (cannot find type FP while parsing argument list)

Running the program should produce the following three lines of output:
----begin----
3
4
5
----end----

Is anyone able to try this out with other C++ compilers?  What do they say?

 Jyrki
----
Jyrki Tuomi                    |  "The only bright side to this [global envi-
         jjt@cs.uta.fi         |  ronment pollution] is that eventually there
     University of Tampere     |  may not be a piece of the planet worth
Department of Computer Science |  fighting over"  --  Calvin

----begin----begin----begin----begin----begin----begin----begin----begin----
// list.cpp, original code by Arto V. Viitanen (av@cs.uta.fi)
//
// BCC 4.0 issues the error message:
// Error LIST.CPP 71: 'list<int>::FP' is not accessible
// (Note that this file has only 69 lines!)
//
// gcc 2.5.8 issues the error message:
// list.cpp:51: `FP' was not declared in this scope
// (FP should be visible while parsing the argument list for 'walkthrough')
//
#include <iostream.h>

// class declaration
template<class Item> class list {
    typedef void (*FP)(Item);
    struct node {
        Item contents;
        node* next;
    };

    node* first;
    node* last;
public:
    list() {first = last = 0;}
    ~list();
    void add(Item thing);
    void walkthrough(FP f);
};

// member function definitions
template<class Item> list<Item>::~list() {
    node* s = first;
    while (s) {
        node* aid = s;
        s = s->next;
        delete aid;
    }
}

template<class Item> void list<Item>::add(Item thing) {
    node* s = new node;
    s->contents = thing;
    s->next = 0;
    if (last)
        last->next = s;
    last = s;
    if (!first)
        first = s;
}

template<class Item> void list<Item>::walkthrough(FP f) {
    for(node* s = first; s; s = s->next)                   // line 52
        f(s->contents);
}

void print(int x) {
    cout << x << endl;
}

// a small test program
void main() {
    list<int> ls;

    ls.add(3);
    ls.add(4);
    ls.add(5);
    ls.walkthrough(print);
}
// line 69
----end----end----end----end----end----end----end----end----end----end----
--
Jyrki Tuomi                    |  "The only bright side to this [global envi-
         jjt@cs.uta.fi         |  ronment pollution] is that eventually there
     University of Tampere     |  may not be a piece of the planet worth
Department of Computer Science |  fighting over"  --  Calvin