> Pierre Guyot at pmaguyot@mon.adresse.est.ailleurs.net.invalid wrote on
> 8/18/05 3:08 PM:
[quoted text clipped - 29 lines]
>
> I guess I'll have to break down and read the standard on this.
I haven't *quite* consulted the standard (but see below), but I've confirmed
that in non-Mach-O targets CodeWarrior's dynamic_cast supports the side-ways
casting that I expected. Behavior of released applications indicate that
this behavior has worked since early 2000.
The debugger's display of 0xFFFFFFFF as the dynamic_cast result in
non-Mach-O targets is apparently a debugger fluke, wherein displayed value
behavior suggests that optimization is turned on when in fact all
optimization is off. I'll save that issue for a separate thread.
Only in the new Mach-O target is dynamic_cast returning 0 in this case. So
this is at least an inconsistency in the Mach-O implementation, if not a
violation of the standard.
Regarding the standard, I could not find the C++ standard online just now,
only the 1997 public-review document, but it seems to support my case:
> 5.2.7 Dynamic cast [expr.dynamic.cast]
>
[quoted text clipped - 3 lines]
> defined in a dynamic_cast. The dynamic_cast operator shall not cast
> away constness (_expr.const.cast_).
[snip]
> 8 The run-time check logically executes as follows:
>
[quoted text clipped - 11 lines]
>
> --Otherwise, the run-time check fails.
Mapping this onto my example (see quoted material above for full details):
B *b = dynamic_cast<B *> (this);
T maps to B and v maps to "this".
In my reading it is the 2nd ("Otherwise") paragraph that covers my
situation. I'll requote that paragraph with my notes added:
> --Otherwise, if v
"this"
> points (refers) to a public base class sub-object of
> the most derived object,
the complete object of class "A"
> and the type of the most derived object
namely A
> has an unambiguous public base class of type T,
in this case T maps to B, so this is satisfied because A has an unambiguous
public base class of type B
> the result is a pointer
> (an lvalue referring) to the T sub-object of the most derived
> object.
So the result is a pointer to the B sub-object of the A object.
So I tentatively think the Mach-O implementation of dynamic_cast is buggy.
(Can someone confirm that this thinking is correct?) And in any case it
does not support dynamic_cast behavior that is supported in CFM targets.
Thanks.
-Kurt Bigler