Author: Raphael Isemann Date: 2020-02-11T10:47:42+01:00 New Revision: 70fb447ca012728dbfa49a82136554630e188229
URL: https://github.com/llvm/llvm-project/commit/70fb447ca012728dbfa49a82136554630e188229 DIFF: https://github.com/llvm/llvm-project/commit/70fb447ca012728dbfa49a82136554630e188229.diff LOG: [lldb] Add test for C++ constructor calls from the expression evaluator Added: lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/Makefile lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/TestCppConstructors.py lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/main.cpp Modified: Removed: ################################################################################ diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/Makefile b/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/Makefile new file mode 100644 index 000000000000..99998b20bcb0 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/TestCppConstructors.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/TestCppConstructors.py new file mode 100644 index 000000000000..422854e38de1 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/TestCppConstructors.py @@ -0,0 +1,26 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_constructors(self): + self.build() + lldbutil.run_to_source_breakpoint(self,"// break here", lldb.SBFileSpec("main.cpp")) + self.expect_expr("ClassWithImplicitCtor().foo()", result_type="int", result_value="1") + self.expect_expr("ClassWithMultipleCtor(3).value", result_type="int", result_value="3") + self.expect_expr("ClassWithMultipleCtor(3, 1).value", result_type="int", result_value="4") + + self.expect_expr("ClassWithDeletedCtor().value", result_type="int", result_value="6") + self.expect_expr("ClassWithDeletedDefaultCtor(7).value", result_type="int", result_value="7") + + # FIXME: It seems we try to call the non-existent default constructor here which is wrong. + self.expect("expr ClassWithDefaultedCtor().foo()", error=True, substrs="Couldn't lookup symbols:") + + # FIXME: Calling deleted constructors should fail before linking. + self.expect("expr ClassWithDeletedCtor(1).value", error=True, substrs=["Couldn't lookup symbols:"]) + self.expect("expr ClassWithDeletedDefaultCtor().value", error=True, substrs=["Couldn't lookup symbols:"]) + diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/main.cpp new file mode 100644 index 000000000000..4e69b58abb00 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/constructors/main.cpp @@ -0,0 +1,45 @@ +struct ClassWithImplicitCtor { + int foo() { return 1; } +}; + +struct ClassWithDefaultedCtor { + ClassWithDefaultedCtor() = default; + int foo() { return 2; } +}; + +struct ClassWithOneCtor { + int value; + ClassWithOneCtor(int i) { value = i; } +}; + +struct ClassWithMultipleCtor { + int value; + ClassWithMultipleCtor(int i) { value = i; } + ClassWithMultipleCtor(int i, int v) { value = v + i; } +}; + +struct ClassWithDeletedCtor { + int value; + ClassWithDeletedCtor() { value = 6; } + ClassWithDeletedCtor(int i) = delete; +}; + +struct ClassWithDeletedDefaultCtor { + int value; + ClassWithDeletedDefaultCtor() = delete; + ClassWithDeletedDefaultCtor(int i) { value = i; } +}; + +int main() { + ClassWithImplicitCtor C1; + C1.foo(); + ClassWithDefaultedCtor C2; + C2.foo(); + ClassWithOneCtor C3(22); + ClassWithMultipleCtor C4(23); + ClassWithMultipleCtor C5(24, 25); + ClassWithDeletedCtor C6; + ClassWithDeletedDefaultCtor C7(26); + + return 0; // break here +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits