[mlir][PDLL] Allow (and ignore) `-D` tablegen macros. (#124166)
[llvm-project.git] / lldb / test / API / lang / cpp / virtual-functions / main.cpp
blob6f6c9e6b41c48b492ea17d61839282f9439f01cb
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.
5 struct BaseWithVirtDtor {
6 virtual ~BaseWithVirtDtor() {}
7 virtual int foo() { return 1; }
8 };
10 struct BaseWithoutVirtDtor {
11 virtual int foo() { return 2; }
14 struct DerivedWithVirtDtor : BaseWithVirtDtor {
15 virtual ~DerivedWithVirtDtor() {}
16 virtual int foo() { return 3; }
19 struct DerivedWithoutVirtDtor : BaseWithoutVirtDtor {
20 virtual int foo() { return 4; }
23 struct DerivedWithBaseVirtDtor : BaseWithVirtDtor {
24 virtual int foo() { return 5; }
27 struct DerivedWithVirtDtorButNoBaseDtor : BaseWithoutVirtDtor {
28 virtual ~DerivedWithVirtDtorButNoBaseDtor() {}
29 virtual int foo() { return 6; }
32 struct DerivedWithOverload : BaseWithVirtDtor {
33 virtual ~DerivedWithOverload() {}
34 virtual int foo(int i) { return 7; }
37 struct DerivedWithOverloadAndUsing : BaseWithVirtDtor {
38 virtual ~DerivedWithOverloadAndUsing() {}
39 using BaseWithVirtDtor::foo;
40 virtual int foo(int i) { return 8; }
43 int main() {
44 // Declare base classes.
45 BaseWithVirtDtor base_with_dtor;
46 BaseWithoutVirtDtor base_without_dtor;
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;
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;
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();
69 return i; // break here