1 // { dg-do run } 2 3 // Copyright (C) 2002 Free Software Foundation, Inc. 4 // Contributed by Nathan Sidwell 27 Nov 2002 <nathan@codesourcery.com> 5 6 // covariant returns. Virtual offset. 7 8 struct B1; 9 struct B2; 10 struct D; 11 12 struct B1 13 { foo1B114 virtual B1 *foo1 () {return this;} 15 virtual B2 *foo2 (D *); 16 }; 17 struct B2 18 { baz1B219 virtual B2 *baz1 () {return this;} 20 virtual B1 *baz2 (D *); 21 }; 22 23 struct D : virtual B1, virtual B2 24 { foo1D25 virtual D *foo1 () {return this;} foo2D26 virtual D *foo2 (D *d) {return d;} baz1D27 virtual D *baz1 () {return this;} baz2D28 virtual D *baz2 (D *d) {return d;} 29 }; 30 foo2(D * d)31B2 *B1::foo2 (D *d) {return d;} baz2(D * d)32B1 *B2::baz2 (D *d) {return d;} 33 test(B1 * b1,B2 * b2,D * d)34int test (B1 *b1, B2 *b2, D *d) 35 { 36 if (b1->foo1 () != b1) 37 return 1; 38 if (b2->baz1 () != b2) 39 return 2; 40 if (b1->foo2 (d) != b2) 41 return 3; 42 if (b2->baz2 (d) != b1) 43 return 4; 44 return 0; 45 } 46 test(D * d)47int test (D *d) 48 { 49 if (d->foo2 (d) != d) 50 return 11; 51 if (d->baz2 (d) != d) 52 return 12; 53 if (d->foo1 () != d) 54 return 13; 55 if (d->baz1 () != d) 56 return 14; 57 return 0; 58 } 59 main()60int main () 61 { 62 D d; 63 int r; 64 65 if ((r = test (&d, &d, &d))) 66 return r; 67 if ((r = test (&d))) 68 return r; 69 return 0; 70 } 71