Virtual Mem Func Ptr Call Fails When Base Class Has No Vtable
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Thu Sep 30 19:57:00 GMT 1999
> Err... The C++ Standard says [expr.static.cast]:
I see. Learn something new about C++ every day :-)
> Since the class B is a base of the class containing the original
> member, the old-style cast should succeed as a static_cast, and should
> not invoke undefined behavior.
The bug appears is that g++ just *knows* that the pointer-to-member
won't call a virtual function, if the class doesn't have virtual
functions. If the example is right, this assumption is wrong. Removing
the fragment
if (TYPE_SIZE (basetype) != NULL_TREE
&& ! TYPE_VIRTUAL_P (basetype))
/* If basetype doesn't have virtual functions, don't emit code to
handle that case. */
e1 = e3;
else
from typeck.c fixes the bug.
> I seem to recall some wording in the Standard (or some earlier WP)
> that would make the *use* of this pointer-to-member undefined unless
> it was declared as virtual in the case class, but I can't find it any
> more. Can anybody?
I couldn't. Furthermore, I could not even find the statement that a
pointer-to-member call should consider virtuality. If somebody tells
me where that is, I produce a patch.
It would be a pity, though - this is such a nice optimization :-)
Regards,
Martin
More information about the Gcc-bugs
mailing list