xref: /llvm-project/lldb/test/API/lang/cpp/function-local-class/TestCppFunctionLocalClass.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1cda1450fSRaphael Isemannimport lldb
2cda1450fSRaphael Isemannfrom lldbsuite.test.decorators import *
3cda1450fSRaphael Isemannfrom lldbsuite.test.lldbtest import *
4cda1450fSRaphael Isemannfrom lldbsuite.test import lldbutil
5cda1450fSRaphael Isemann
6cda1450fSRaphael Isemann
7*2238dcc3SJonas Devlieghereclass TestCase(TestBase):
8cda1450fSRaphael Isemann    @no_debug_info_test
9cda1450fSRaphael Isemann    def test(self):
10cda1450fSRaphael Isemann        self.build()
11*2238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
12*2238dcc3SJonas Devlieghere            self, "// break here", lldb.SBFileSpec("main.cpp")
13*2238dcc3SJonas Devlieghere        )
14cda1450fSRaphael Isemann
15*2238dcc3SJonas Devlieghere        m_val = self.expect_expr(
16*2238dcc3SJonas Devlieghere            "m",
17*2238dcc3SJonas Devlieghere            result_type="WithMember",
18*2238dcc3SJonas Devlieghere            result_children=[ValueCheck(name="i", value="1")],
19*2238dcc3SJonas Devlieghere        )
20cda1450fSRaphael Isemann        # FIXME: The non-display name doesn't include the function, so users
21cda1450fSRaphael Isemann        # can't actually match specific classes by their name. Either document
22cda1450fSRaphael Isemann        # or fix this.
23cda1450fSRaphael Isemann        self.assertEqual(m_val.GetType().GetName(), "WithMember")
24cda1450fSRaphael Isemann        # Try accessing the type in the expression evaluator.
25cda1450fSRaphael Isemann        self.expect_expr("m.i", result_type="int", result_value="1")
26cda1450fSRaphael Isemann
27*2238dcc3SJonas Devlieghere        self.expect_expr(
28*2238dcc3SJonas Devlieghere            "typedef_unnamed",
29*2238dcc3SJonas Devlieghere            result_type="TypedefUnnamed",
30*2238dcc3SJonas Devlieghere            result_children=[ValueCheck(name="a", value="2")],
31*2238dcc3SJonas Devlieghere        )
32*2238dcc3SJonas Devlieghere        self.expect_expr(
33*2238dcc3SJonas Devlieghere            "typedef_unnamed2",
34*2238dcc3SJonas Devlieghere            result_type="TypedefUnnamed2",
35*2238dcc3SJonas Devlieghere            result_children=[ValueCheck(name="b", value="3")],
36*2238dcc3SJonas Devlieghere        )
37*2238dcc3SJonas Devlieghere        self.expect_expr(
38*2238dcc3SJonas Devlieghere            "unnamed",
39*2238dcc3SJonas Devlieghere            result_type="(unnamed struct)",
40*2238dcc3SJonas Devlieghere            result_children=[ValueCheck(name="i", value="4")],
41*2238dcc3SJonas Devlieghere        )
42*2238dcc3SJonas Devlieghere        self.expect_expr(
43*2238dcc3SJonas Devlieghere            "unnamed2",
44*2238dcc3SJonas Devlieghere            result_type="(unnamed struct)",
45*2238dcc3SJonas Devlieghere            result_children=[ValueCheck(name="j", value="5")],
46*2238dcc3SJonas Devlieghere        )
47cda1450fSRaphael Isemann
48cda1450fSRaphael Isemann        # Try a class that is only forward declared.
49cda1450fSRaphael Isemann        self.expect_expr("fwd", result_type="Forward *")
50*2238dcc3SJonas Devlieghere        self.expect(
51*2238dcc3SJonas Devlieghere            "expression -- fwd->i",
52*2238dcc3SJonas Devlieghere            error=True,
53*2238dcc3SJonas Devlieghere            substrs=["member access into incomplete type 'Forward'"],
54*2238dcc3SJonas Devlieghere        )
55*2238dcc3SJonas Devlieghere        self.expect(
56*2238dcc3SJonas Devlieghere            "expression -- *fwd",
57*2238dcc3SJonas Devlieghere            error=True,
58*2238dcc3SJonas Devlieghere            substrs=["incomplete type 'Forward' where a complete type is required"],
59*2238dcc3SJonas Devlieghere        )
60cda1450fSRaphael Isemann
61cda1450fSRaphael Isemann        # Try a class that has a name that matches a class in the global scope.
62cda1450fSRaphael Isemann        self.expect_expr("fwd_conflict", result_type="ForwardConflict *")
63cda1450fSRaphael Isemann        # FIXME: This pulls in the unrelated type with the same name from the
64cda1450fSRaphael Isemann        # global scope.
65*2238dcc3SJonas Devlieghere        self.expect(
66*2238dcc3SJonas Devlieghere            "expression -- fwd_conflict->i",
67*2238dcc3SJonas Devlieghere            error=True,
68*2238dcc3SJonas Devlieghere            substrs=[
69cda1450fSRaphael Isemann                # This should point out that ForwardConflict is incomplete.
70cda1450fSRaphael Isemann                "no member named 'i' in 'ForwardConflict'"
71*2238dcc3SJonas Devlieghere            ],
72*2238dcc3SJonas Devlieghere        )
73*2238dcc3SJonas Devlieghere        self.expect(
74*2238dcc3SJonas Devlieghere            "expression -- *fwd_conflict",
75*2238dcc3SJonas Devlieghere            error=True,
76*2238dcc3SJonas Devlieghere            substrs=[
77cda1450fSRaphael Isemann                # This should fail to parse instead.
78cda1450fSRaphael Isemann                "couldn't read its memory"
79*2238dcc3SJonas Devlieghere            ],
80*2238dcc3SJonas Devlieghere        )
81