Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!uupsi!sunic!chalmers.se!appli!niklas From: niklas@appli.se (Niklas Hallqvist) Newsgroups: comp.lang.c++ Subject: Re: multiple inheritance bug Message-ID: <1273@appli.se> Date: 15 Feb 91 03:29:28 GMT References: <3553@island.COM> <9592@dog.ee.lbl.gov> <1991Feb11.213836.1840@lia> Organization: Applitron Datasystem AB, GOTHENBURG, SWEDEN Lines: 67 In article <1991Feb11.213836.1840@lia> jgro@lia.com (Jeremy Grodberg) writes: >In article <9592@dog.ee.lbl.gov> beard@ux5.lbl.gov (Patrick C Beard) writes: >>In article <3553@island.COM> lars@island.COM (Lars Nyman) writes: >># >>#I have a problem with multiple inheritance using virtual base classes, and >>#suspect it's a bug in the C++ compiler. >> >>Don't be so quick to call this a bug. It's actually a feature. C++ does >>not officially support the calling of virtual functions from a constructor. >You are wrong, Mr. Beard. ARM 12.7 clearly says > > Member functions may be called in constructors and destructors. This > implies that virtual functions may be called (directly or indirectly). > The function called will be the one defined in the constructor's > (or destructor's) own class or its bases, but *not* any > function overriding it in a derived class. [...] The effect of calling > a pure virtual function directly or indirectly for the object being > constructed from a constructor, except using explicit qualification, > is undefined. I haven't got my ARM with my at this moment (but still both of my hands keep writing :-), so I couldn't check out the context of the statement above. I suppose the intended meaning is that you can't expect anything useful to be done if you call a virtual function from a constructor, if the function is declared as pure in the class where the constructor WAS FOUND. Clearly, if the function was pure in one (or more) of this class' bases, but defined in this class, the effect MUST be well-defined. As english is not my first language (neither Bjarne's), I have some difficulties in understanding the last sentence of the quote above, maybe it has to be clarified (Are you listening, ANSI-committe-members?). >So, Mr. Beard, you are totally wrong in saying C++ does not offically >support the calling of virtual functions from a constructor. >However, Mr. Nyman's example code did involve calling a pure virtual >function indirectly for the object being constructed from a constructor, >without explicit qualification, so he has no reason to claim his sample >code should work. The virtual function which was called, was pure in one of the BASES of the class where the constructor was found, but DEFINED IN the class! As I stated above, I think this is VERY legal. Why shouldn't it be so? >Also, since Mr. Nyman didn't include the output of his sample code in his >posting, it is hard to know if the problem was the code not working as >it should, or Mr. Nyman not understanding what the code should do. >Another test, without the pure virtual function, is called for before >calling this a bug. He wrote a rather technical description of the bug (yes, I think it's one) which seemed quite clear to me: The vtable was incorrect when the object were constructed (or destroyed). He also made clear that he knew that an object's dynamic type in a constructor is equal to the type (class) where the constructor was found, and if he knew that it's easy to deduce what he thought program should do. As to the called for test, I agree, but even if that would work, I think it's a bug. G++ fails with his program but works if the virtual DERIVATION of Shape is made non-virtual, as I've reported to FSF. Niklas -- Niklas Hallqvist Phone: +46-(0)31-40 75 00 Applitron Datasystem Fax: +46-(0)31-83 39 50 Molndalsvagen 95 Email: niklas@appli.se S-412 63 GOTEBORG, Sweden mcsun!sunic!chalmers!appli!niklas