Xref: utzoo comp.sys.sgi:8878 comp.lang.c++:12274 Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!uwm.edu!spool.mu.edu!uunet!contex!jeff From: jeff@contex.UUCP (Jeff Carey) Newsgroups: comp.sys.sgi,comp.lang.c++ Subject: BUG when initializing with a 'const' with SGI C++ 2.0 Keywords: bug virtual const c++ sgi initialization constructor Message-ID: <1698@contex.UUCP> Date: 15 Mar 91 22:42:34 GMT Followup-To: comp.sys.sgi Organization: Xyvision Design Systems, Wakefield MA Lines: 61 I am using: System release: IRIX Release 4D1-3.3.1 C++ release: S4-C++-2.0 Software Option: C++ Translator Version 2.0 on a Silicon Graphics PI. Here is some code that illustrates a bug that I ran into recently. The bug has to do with "some_const" being a 'const'; the bug disappears when "some_const" is a '#define' macro. ---------------------- beginning of test.c++ code ---------------------------- #define BUG 1 #if BUG const int some_const = 0; #else #define some_const 0 #endif class V { public: V(); V(int); }; class A : virtual public V { public: A(int); }; class B { public: B(int); }; class C : public A, public B { public: C() : V(0), A(some_const), B(0) {} }; ----------------------------- end of test code ------------------------------- The code does not compile when "some_const" is a 'const'. Ouch --- jeff p.s. IMPORTANT NOTE: I assume the SGI (AT&T) bug fixers know that currently this compiler will not accept a 'virtual base class' unless it has a 'default initializer' declared; this is strange, because you can get around having to actually define the function in most (all) cases -- just declare it ?!!! By the way, this is why I have "V::V()" declared above; ideally, I would not have had it there. UNIX System V AT&T C++ Language System Release 2.0, Product Reference Manual, Select Code 307-146, section 12.6.2, p. 82, states that, and I paraphrase, "virtual base classes must have a default constructor or no constructor [only] if the constructor of a most derived class does not specify a mem-initializer for a virtual base class." I know the ARM talks about this too, but I didn't take the time to look it up, sorry. Geez --- jeff -- ------------------------ Jeff Carey contex!jeff@uunet.uu.net