[Mono-dev] Segfault on base class method access
Robert Jordan
robertj at gmx.net
Wed Nov 28 10:53:58 EST 2007
Paul Melis wrote:
> Hello,
>
> I tried to register at the bug tracker, but did not receive a
> confirmation mail, so I post here instead.
>
> When running the code below mono 1.2.5.2 segfaults. The stack trace is
> not enlightening.
This is a stack overflow. When mono was compiled w/out "alt stack"
support, stack overflows are reported this way.
> The use case here is to prefix a class's string representation with its
> base class's string representation.
> I know about "base", but I figured it only gives you the direct parent
> and not the parent-of-parent.
> Btw, if class A is removed (also as base class to B) then this code
> still segfaults. It seems to be the "this as ..." that's the problem.
[...]
> class C : B
> {
> public override string ToString()
> {
> return String.Format("({0}) C", (this as A).ToString());
> }
> };
You cannot do this, since even if you cast to a base class, the
overridden method will be taken. That's why a "base" call is necessary.
Robert
More information about the Mono-devel-list
mailing list