// Test virtual casts with polymorphic types. /* IMPORTANT: The virtual system has not been finalized. However the * exception system does depend on the work-in-progress version currently * supported. That is also why the tests under the exception directory. */ #include struct mono_base_vtable { mono_base_vtable const * const parent; }; struct mono_base { mono_base_vtable const * virtual_table; }; forall(otype T) struct mono_child_vtable { mono_base_vtable const * const parent; }; forall(otype T) struct mono_child { mono_child_vtable(T) const * virtual_table; }; mono_base_vtable _mono_base_vtable_instance @= { 0 }; mono_child_vtable(int) _mono_child_vtable_instance @= { &_mono_base_vtable_instance }; void mono_poly_test(void) { mono_child(int) child = { &_mono_child_vtable_instance }; mono_base * base = (virtual mono_base *)&child; assert(base); } forall(otype U) struct poly_base_vtable { poly_base_vtable(U) const * const parent; }; forall(otype U) struct poly_base { poly_base_vtable(U) const * virtual_table; }; forall(otype V) struct poly_child_vtable { poly_base_vtable(V) const * const parent; }; forall(otype V) struct poly_child { poly_child_vtable(V) const * virtual_table; }; poly_base_vtable(int) _poly_base_vtable_instance @= { 0 }; poly_child_vtable(int) _poly_child_vtable_instance @= { &_poly_base_vtable_instance }; /* Resolver bug keeps me from adding these. poly_base_vtable(char) _poly_base_vtable_instance @= { 0 }; poly_child_vtable(char) _poly_child_vtable_instance @= { &_poly_base_vtable_instance }; */ void poly_poly_test() { poly_child(int) child = { &_poly_child_vtable_instance }; poly_base(int) * base = (virtual poly_base(int) *)&child; assert(base); } int main(void) { mono_poly_test(); poly_poly_test(); printf( "done\n" ); // non-empty .expect file }