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