xref: /llvm-project/lldb/test/API/lang/cpp/crtp/TestCppCRTP.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1*4019699fSRaphael Isemann"""
2*4019699fSRaphael IsemannA test for the curiously recurring template pattern (or CRTP).
3*4019699fSRaphael Isemann
4*4019699fSRaphael IsemannNote that the derived class is referenced directly from the parent class in the
5*4019699fSRaphael Isemanntest. If this fails then there is a good chance that LLDB tried to eagerly
6*4019699fSRaphael Isemannresolve the definition of the derived class while constructing the base class.
7*4019699fSRaphael Isemann"""
8*4019699fSRaphael Isemann
9*4019699fSRaphael Isemannimport lldb
10*4019699fSRaphael Isemannfrom lldbsuite.test.decorators import *
11*4019699fSRaphael Isemannfrom lldbsuite.test.lldbtest import *
12*4019699fSRaphael Isemannfrom lldbsuite.test import lldbutil
13*4019699fSRaphael Isemann
14*4019699fSRaphael Isemann
15*4019699fSRaphael Isemannclass TestCase(TestBase):
16*4019699fSRaphael Isemann    @no_debug_info_test
17*4019699fSRaphael Isemann    def test(self):
18*4019699fSRaphael Isemann        self.build()
19*4019699fSRaphael Isemann        self.createTestTarget()
20*4019699fSRaphael Isemann
21*4019699fSRaphael Isemann        # Try using the class in the expression evaluator.
22*4019699fSRaphael Isemann        self.expect_expr(
23*4019699fSRaphael Isemann            "derived",
24*4019699fSRaphael Isemann            result_type="Derived",
25*4019699fSRaphael Isemann            result_children=[
26*4019699fSRaphael Isemann                ValueCheck(name="Base<Derived>"),
27*4019699fSRaphael Isemann                ValueCheck(name="member", value="0"),
28*4019699fSRaphael Isemann            ],
29*4019699fSRaphael Isemann        )
30*4019699fSRaphael Isemann
31*4019699fSRaphael Isemann        # Try accessing the members of the class and base class.
32*4019699fSRaphael Isemann        self.expect_expr("derived.pointer", result_type="Derived *")
33*4019699fSRaphael Isemann        self.expect_expr("derived.member", result_type="int", result_value="0")
34