brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 6f6c9e6 Raw
71 lines · cpp
1// Tests virtual function calls. As virtual destructors influence2// vtables this tests also needs to cover all combinations of3// virtual destructors in the derived/base class.4 5struct BaseWithVirtDtor {6  virtual ~BaseWithVirtDtor() {}7  virtual int foo() { return 1; }8};9 10struct BaseWithoutVirtDtor {11  virtual int foo() { return 2; }12};13 14struct DerivedWithVirtDtor : BaseWithVirtDtor {15  virtual ~DerivedWithVirtDtor() {}16  virtual int foo() { return 3; }17};18 19struct DerivedWithoutVirtDtor : BaseWithoutVirtDtor {20  virtual int foo() { return 4; }21};22 23struct DerivedWithBaseVirtDtor : BaseWithVirtDtor {24  virtual int foo() { return 5; }25};26 27struct DerivedWithVirtDtorButNoBaseDtor : BaseWithoutVirtDtor {28  virtual ~DerivedWithVirtDtorButNoBaseDtor() {}29  virtual int foo() { return 6; }30};31 32struct DerivedWithOverload : BaseWithVirtDtor {33  virtual ~DerivedWithOverload() {}34  virtual int foo(int i) { return 7; }35};36 37struct DerivedWithOverloadAndUsing : BaseWithVirtDtor {38  virtual ~DerivedWithOverloadAndUsing() {}39  using BaseWithVirtDtor::foo;40  virtual int foo(int i) { return 8; }41};42 43int 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(1)66          + derived_with_overload_and_using.foo(2)67          + derived_with_overload_and_using.foo();68 69  return i; // break here70}71