[Bug c++/13005] [3.3/3.4 Regresssion] [aliasing] Pointer wrongly adjusted for derived class containing virtual function

stephenma at telus dot net gcc-bugzilla@gcc.gnu.org
Wed Dec 31 09:48:00 GMT 2003


------- Additional Comments From stephenma at telus dot net  2003-12-31 08:53 -------
Nathan Sidwell refers to [5.4]/6's explicit disclaimer about the casting of
incomplete types.  He is technically correct, but only with respect to the Draft
ANSI C++ Standard (1996).

There is an enormous legacy of *working* programs that follow the older ARM
standard, as defined in the Annotated C++ Reference Manual by Ellis and
Stroustrup.  Silently breaking these programs, as g++ 3.x does in the case I
stumbled upon, is probably asking for trouble.  Perhaps g++ needs an -fARM
switch for compatibility.

Here is some evidence that my test program is correct with respect to the ARM. 
Section 10.3c begins by saying "With multiple inheritance, casting may change
the value of a pointer".  Section 5.4 contains the following sentence: "It
follows that where multiple inheritance is involved casting to and from
undefined types is best avoided" (page 69 of the hardcover edition).  The clear
implication is that when there is only single inheritance, casting back and
forth between base and derived pointers always yields valid pointers, even when
the types are incomplete.  And indeed, this works properly in g++ 2.95.

A minor consideration is that by locating Base at a nonzero offset in Derived,
g++ 3.3 is imposing multiple inheritance overhead even in the single inheritance
case.  The situation I discovered may not be all that rare, so the inefficiency
could be uncomfortable to some people.

I realize that changing the object layout again will not be fun.  And yet we
have all these legacy programs to worry about.  How can we solve this problem?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13005



More information about the Gcc-bugs mailing list