[lldb] Add test for calling overloaded virtual functions

This commit is contained in:
Raphael Isemann 2020-02-11 11:28:14 +01:00
parent e7755f9e4f
commit 6909c2e88d
2 changed files with 24 additions and 1 deletions

View File

@ -29,3 +29,11 @@ class TestCase(TestBase):
self.expect_expr("derived_without_as_base.foo()", result_type="int", result_value="4")
self.expect_expr("derived_with_base_dtor_as_base.foo()", result_type="int", result_value="5")
self.expect_expr("derived_with_dtor_but_no_base_dtor_as_base.foo()", result_type="int", result_value="6")
def test_call_overloaded(self):
self.common_setup()
self.expect("expr derived_with_overload.foo()", error=True, substrs=["too few arguments to function call, expected 1, have 0"])
self.expect_expr("derived_with_overload.foo(1)", result_type="int", result_value="7")
self.expect_expr("derived_with_overload_and_using.foo(1)", result_type="int", result_value="8")
# FIXME: It seems the using declaration doesn't import the overload from the base class.
self.expect("expr derived_with_overload_and_using.foo()", error=True, substrs=["too few arguments to function call, expected 1, have 0"])

View File

@ -29,6 +29,17 @@ struct DerivedWithVirtDtorButNoBaseDtor : BaseWithoutVirtDtor {
virtual int foo() { return 6; }
};
struct DerivedWithOverload : BaseWithVirtDtor {
virtual ~DerivedWithOverload() {}
virtual int foo(int i) { return 7; }
};
struct DerivedWithOverloadAndUsing : BaseWithVirtDtor {
virtual ~DerivedWithOverloadAndUsing() {}
using BaseWithVirtDtor::foo;
virtual int foo(int i) { return 8; }
};
int main() {
// Declare base classes.
BaseWithVirtDtor base_with_dtor;
@ -39,6 +50,8 @@ int main() {
DerivedWithoutVirtDtor derived_without_dtor;
DerivedWithBaseVirtDtor derived_with_base_dtor;
DerivedWithVirtDtorButNoBaseDtor derived_with_dtor_but_no_base_dtor;
DerivedWithOverload derived_with_overload;
DerivedWithOverloadAndUsing derived_with_overload_and_using;
// The previous classes as their base class type.
BaseWithVirtDtor &derived_with_dtor_as_base = derived_with_dtor;
@ -49,7 +62,9 @@ int main() {
// Call functions so that they are compiled.
int i = base_with_dtor.foo() + base_without_dtor.foo() +
derived_with_dtor.foo() + derived_without_dtor.foo() +
derived_with_base_dtor.foo();
derived_with_base_dtor.foo() + derived_with_overload.foo(1)
+ derived_with_overload_and_using.foo(2)
+ derived_with_overload_and_using.foo();
return i; // break here
}