Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!usc!rutgers!att!tellab5!wheaton!obdient!gill!paul From: paul@gill.UUCP (Paul Nordstrom) Newsgroups: comp.lang.c++ Subject: type compatibility Keywords: compilers Message-ID: <754@gill.UUCP> Date: 26 Nov 89 17:52:18 GMT Organization: Gill & Co., L.P., Chicago, IL Lines: 62 While attempting to port InterViews to the Oregon C++ compiler, I came across the following code (simplified drastically): typedef const void* TextData; static TextData SELF = (void*)-1; class Text { public: Text(TextData context = SELF); protected: TextData context; int size; }; class Whitespace : public Text { public: Whitespace(int size, TextData context = SELF); virtual Text* Copy(); }; Text* Whitespace::Copy () { #ifdef OREGON if ( context == this ) return new Whitespace(size, SELF); else return new Whitespace(size, context); #else return new Whitespace(size, context==this ? SELF : context); #endif } The portion of code that is compiled when OREGON is defined compiles (presumably) correctly under Oregon C++ (1.2Ag). The #else side is the code is as distributed in the Interviews release currently on uunet. Obviously (he says blithely :-) ) the two sections of code are equivalent. The Oregon compiler ("occ") yields the following error message on the original code: 27 * return new Whitespace(size, context==this ? SELF : context); ^203 *** 203: Error: Operands are of differing or incompatible type In case the spacing gets garbled, the ^203 is pointing to the question mark in the line of code, indicating that that is where the compiler thinks the error is. Assuming that I am correct that the two pieces of code are in fact equivalent, clearly occ has a bug of some kind: one piece compiles, one does not. My question is: are both pieces of code correct, or both incorrect. The issue I see is: should the compiler allow the test "context==this" when context is a void* and this is a Whitespace* ? Any comments, anyone? -- Paul Nordstrom Gill & Co., L.P. uunet!gill!paul