Test cases for sharing virtual base vptrs 2 of 3.

Coleen Phillimore coleen at zko.dec.com
Thu Jan 13 16:39:08 UTC 2000


/*
Test case for sharing virtual bases.
In Most_Derived,
the primary base class is Nonvirt1,
Nonvirt2 and Nonvirt3 share vptrs with
virtual base Shared_Virt.  Shared_Virt
should be at the same offset as Nonvirt2.
Should get:
67% a.out
(long)(Nonvirt1 *)dd - (long)dd = 0
(long)(Nonvirt2 *)dd - (long)dd = 8
(long)(Nonvirt3 *)dd - (long)dd = 16
(long)(Shared_Virt *)dd - (long)dd = 8
*/

struct Shared_Virt {
    virtual void foo();
};
struct Nonvirt2 : virtual Shared_Virt {
	virtual void bar();
};
struct Nonvirt3 : virtual Shared_Virt {
	virtual void baz();
};

struct Nonvirt1 {
	virtual void foo();
};

struct Most_Derived : Nonvirt1, Nonvirt2, Nonvirt3 {
	virtual void bar();
};

void Shared_Virt::foo() {}
void Nonvirt2::bar() {}
void Nonvirt3::baz() {}
void Nonvirt1::foo() {}
void Most_Derived::bar() {}


extern "C" int printf(const char *,...);
#define EVAL(EXPR) printf( #EXPR " = %d\n", (EXPR) );
main()
{
  Most_Derived *dd = new Most_Derived;
  EVAL((long)(Nonvirt1 *)dd - (long)dd);
  EVAL((long)(Nonvirt2 *)dd - (long)dd);
  EVAL((long)(Nonvirt3 *)dd - (long)dd);
  EVAL((long)(Shared_Virt *)dd - (long)dd);
}




More information about the cxx-abi-dev mailing list