| 1 | // Tests virtual function calls. As virtual destructors influence |
|---|---|
| 2 | // vtables this tests also needs to cover all combinations of |
| 3 | // virtual destructors in the derived/base class. |
| 4 | |
| 5 | struct BaseWithVirtDtor { |
| 6 | virtual ~BaseWithVirtDtor() {} |
| 7 | virtual int foo() { return 1; } |
| 8 | }; |
| 9 | |
| 10 | struct BaseWithoutVirtDtor { |
| 11 | virtual int foo() { return 2; } |
| 12 | }; |
| 13 | |
| 14 | struct DerivedWithVirtDtor : BaseWithVirtDtor { |
| 15 | virtual ~DerivedWithVirtDtor() {} |
| 16 | virtual int foo() { return 3; } |
| 17 | }; |
| 18 | |
| 19 | struct DerivedWithoutVirtDtor : BaseWithoutVirtDtor { |
| 20 | virtual int foo() { return 4; } |
| 21 | }; |
| 22 | |
| 23 | struct DerivedWithBaseVirtDtor : BaseWithVirtDtor { |
| 24 | virtual int foo() { return 5; } |
| 25 | }; |
| 26 | |
| 27 | struct DerivedWithVirtDtorButNoBaseDtor : BaseWithoutVirtDtor { |
| 28 | virtual ~DerivedWithVirtDtorButNoBaseDtor() {} |
| 29 | virtual int foo() { return 6; } |
| 30 | }; |
| 31 | |
| 32 | struct DerivedWithOverload : BaseWithVirtDtor { |
| 33 | virtual ~DerivedWithOverload() {} |
| 34 | virtual int foo(int i) { return 7; } |
| 35 | }; |
| 36 | |
| 37 | struct DerivedWithOverloadAndUsing : BaseWithVirtDtor { |
| 38 | virtual ~DerivedWithOverloadAndUsing() {} |
| 39 | using BaseWithVirtDtor::foo; |
| 40 | virtual int foo(int i) { return 8; } |
| 41 | }; |
| 42 | |
| 43 | int main() { |
| 44 | // Declare base classes. |
| 45 | BaseWithVirtDtor base_with_dtor; |
| 46 | BaseWithoutVirtDtor base_without_dtor; |
| 47 | |
| 48 | // Declare all the derived classes. |
| 49 | DerivedWithVirtDtor derived_with_dtor; |
| 50 | DerivedWithoutVirtDtor derived_without_dtor; |
| 51 | DerivedWithBaseVirtDtor derived_with_base_dtor; |
| 52 | DerivedWithVirtDtorButNoBaseDtor derived_with_dtor_but_no_base_dtor; |
| 53 | DerivedWithOverload derived_with_overload; |
| 54 | DerivedWithOverloadAndUsing derived_with_overload_and_using; |
| 55 | |
| 56 | // The previous classes as their base class type. |
| 57 | BaseWithVirtDtor &derived_with_dtor_as_base = derived_with_dtor; |
| 58 | BaseWithoutVirtDtor &derived_without_as_base = derived_without_dtor; |
| 59 | BaseWithVirtDtor &derived_with_base_dtor_as_base = derived_with_base_dtor; |
| 60 | BaseWithoutVirtDtor &derived_with_dtor_but_no_base_dtor_as_base = derived_with_dtor_but_no_base_dtor; |
| 61 | |
| 62 | // Call functions so that they are compiled. |
| 63 | int i = base_with_dtor.foo() + base_without_dtor.foo() + |
| 64 | derived_with_dtor.foo() + derived_without_dtor.foo() + |
| 65 | derived_with_base_dtor.foo() + derived_with_overload.foo(i: 1) |
| 66 | + derived_with_overload_and_using.foo(i: 2) |
| 67 | + derived_with_overload_and_using.foo(); |
| 68 | |
| 69 | return i; // break here |
| 70 | } |
| 71 |
