[Lldb-commits] [lldb] 6909c2e - [lldb] Add test for calling overloaded virtual functions

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 11 02:36:48 PST 2020


Author: Raphael Isemann
Date: 2020-02-11T11:36:26+01:00
New Revision: 6909c2e88d0b60e608237f55149bc09d74be47c5

URL: https://github.com/llvm/llvm-project/commit/6909c2e88d0b60e608237f55149bc09d74be47c5
DIFF: https://github.com/llvm/llvm-project/commit/6909c2e88d0b60e608237f55149bc09d74be47c5.diff

LOG: [lldb] Add test for calling overloaded virtual functions

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/TestCppVirtualFunctions.py
    lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/main.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/TestCppVirtualFunctions.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/TestCppVirtualFunctions.py
index d81435421f82..32c4d3513974 100644
--- a/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/TestCppVirtualFunctions.py
+++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/TestCppVirtualFunctions.py
@@ -29,3 +29,11 @@ def test_call_on_derived_as_base(self):
         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"])

diff  --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/main.cpp
index 3689828b2bb9..6f6c9e6b41c4 100644
--- a/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/main.cpp
+++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/virtual-functions/main.cpp
@@ -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
 }


        


More information about the lldb-commits mailing list