kempf@tci.bell-atl.com (Cory Kempf) (09/29/89)
I have either found two bugs in g++, or I don't quite understand C++ yet.
Could someone who understands this stuff a bit better tell me which
it is? (and explain it to me)
------------
the result:
Snoopy 166> g++ -o Bug Bug.cc
Snoopy 167> Bug
Lvl1 test
Level 1.2 test
Level 1.2.1 test
Lvl1 test [ Bug? #1 I think this should print "Level 1.2.1 test"]
Snoopy 168> g++ -DBUG -o Bug2 Bug.cc
Failed assertion TREE_CODE (field) == FIELD_DECL at line 4191 of `cplus-class.c'.
g++: Program cc1plus got fatal signal 6.
Snoopy 169>
--------------
The code:
#include "stream.h"
#include <string.h>
typedef unsigned short ushort;
typedef unsigned long ulong;
typedef unsigned char uchar;
class Lvl1 { // base class
public:
Lvl1() {;} // there
Lvl1(int val) {;}
virtual void writetest() { cerr << "Lvl1 test\n"; }
};
class Lvl1_2 : public Lvl1 {
public:
Lvl1_2() {;}
Lvl1_2(int val) {;}
virtual void writetest() { cerr << "Level 1.2 test\n"; }
};
typedef void Lvl1::(*FP)(); // pointer to method returning void
class Lvl1_2_1 : public Lvl1_2 {
public:
Lvl1_2_1(int val) {;}
virtual void writetest() { cerr << "Level 1.2.1 test\n"; }
void call(FP f) { (*f)(); }
};
main() {
Lvl1 a(1);
Lvl1_2 c(3);
Lvl1_2_1 e(5);
a.writetest();
c.writetest();
e.writetest();
#ifndef BUG
Lvl1 *eq; // pointer to e's base class
#else
Lvl1_2_1 *eq; // pointer to class of e; causes
// compiler to croak
#endif
FP foo; // method pointer
eq = &e;
foo = eq->writetest; // this SHOULD point to
// Lvl1_2_1::writetest,
// Shouldn't it??
e.call(foo); // and this should call it (via
// Lvl1_2_1::call
}
-------------
Thanks in advance,
+C
--
Cory Kempf Technology Concepts phone: (508) 443-7311 x341
uucp: {anywhere}!uunet!tci!kempf, kempf@tci.bell-atl.com
DISCLAIMER: TCI is not responsible for my opinions, nor I for theirs