xref: /llvm-project/lldb/test/API/lang/cpp/constructors/TestCppConstructors.py (revision 6a35ee8077647b32626c3c41f9d9da4dae6670fc)
199451b44SJordan Rupprechtimport lldb
299451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
399451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
499451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
72238dcc3SJonas Devlieghereclass TestCase(TestBase):
8487ac0b3SRaphael Isemann    @expectedFailureAll(bugnumber="llvm.org/pr50814", compiler="gcc")
999451b44SJordan Rupprecht    def test_constructors(self):
1099451b44SJordan Rupprecht        self.build()
112238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
122238dcc3SJonas Devlieghere            self, "// break here", lldb.SBFileSpec("main.cpp")
132238dcc3SJonas Devlieghere        )
142238dcc3SJonas Devlieghere        self.expect_expr(
152238dcc3SJonas Devlieghere            "ClassWithImplicitCtor().foo()", result_type="int", result_value="1"
162238dcc3SJonas Devlieghere        )
172238dcc3SJonas Devlieghere        self.expect_expr(
182238dcc3SJonas Devlieghere            "ClassWithOneCtor(2).value", result_type="int", result_value="2"
192238dcc3SJonas Devlieghere        )
202238dcc3SJonas Devlieghere        self.expect_expr(
212238dcc3SJonas Devlieghere            "ClassWithMultipleCtor(3).value", result_type="int", result_value="3"
222238dcc3SJonas Devlieghere        )
232238dcc3SJonas Devlieghere        self.expect_expr(
242238dcc3SJonas Devlieghere            "ClassWithMultipleCtor(3, 1).value", result_type="int", result_value="4"
252238dcc3SJonas Devlieghere        )
2699451b44SJordan Rupprecht
272238dcc3SJonas Devlieghere        self.expect_expr(
282238dcc3SJonas Devlieghere            "ClassWithDeletedCtor().value", result_type="int", result_value="6"
292238dcc3SJonas Devlieghere        )
302238dcc3SJonas Devlieghere        self.expect_expr(
312238dcc3SJonas Devlieghere            "ClassWithDeletedDefaultCtor(7).value", result_type="int", result_value="7"
322238dcc3SJonas Devlieghere        )
3399451b44SJordan Rupprecht
3499451b44SJordan Rupprecht        # FIXME: It seems we try to call the non-existent default constructor here which is wrong.
352238dcc3SJonas Devlieghere        self.expect(
362238dcc3SJonas Devlieghere            "expr ClassWithDefaultedCtor().foo()",
372238dcc3SJonas Devlieghere            error=True,
382238dcc3SJonas Devlieghere            substrs=["Couldn't look up symbols:"],
392238dcc3SJonas Devlieghere        )
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht        # FIXME: Calling deleted constructors should fail before linking.
422238dcc3SJonas Devlieghere        self.expect(
432238dcc3SJonas Devlieghere            "expr ClassWithDeletedCtor(1).value",
442238dcc3SJonas Devlieghere            error=True,
452238dcc3SJonas Devlieghere            substrs=["Couldn't look up symbols:"],
462238dcc3SJonas Devlieghere        )
472238dcc3SJonas Devlieghere        self.expect(
482238dcc3SJonas Devlieghere            "expr ClassWithDeletedDefaultCtor().value",
492238dcc3SJonas Devlieghere            error=True,
50*6a35ee80SAdrian Prantl            substrs=["Couldn't look up symbols:", "function", "optimized out"],
512238dcc3SJonas Devlieghere        )
5299451b44SJordan Rupprecht
534a9011dcSRaphael Isemann    @skipIfWindows  # Can't find operator new.
542bab1738SRaphael Isemann    @skipIfLinux  # Fails on some Linux systems with SIGABRT.
552bab1738SRaphael Isemann    def test_constructors_new(self):
562bab1738SRaphael Isemann        self.build()
572238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
582238dcc3SJonas Devlieghere            self, "// break here", lldb.SBFileSpec("main.cpp")
592238dcc3SJonas Devlieghere        )
602bab1738SRaphael Isemann
612238dcc3SJonas Devlieghere        self.expect_expr(
622238dcc3SJonas Devlieghere            "(new ClassWithOneCtor(1))->value; 1", result_type="int", result_value="1"
632238dcc3SJonas Devlieghere        )
64