xref: /llvm-project/lldb/test/API/lang/cpp/dereferencing_references/TestCPPDereferencingReferences.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    def test(self):
9        """Tests deferencing lvalue/rvalue references via LLDB's builtin type system."""
10        self.build()
11        lldbutil.run_to_source_breakpoint(
12            self, "// break here", lldb.SBFileSpec("main.cpp")
13        )
14
15        # Take an lvalue reference and call `Dereference` on the SBValue.
16        # The result should be `TTT` (and *not* for example the underlying type
17        # 'int').
18        lref_val = self.expect_var_path("l_ref", type="TTT &")
19        self.assertEqual(lref_val.Dereference().GetType().GetName(), "TTT")
20
21        # Same as above for rvalue references.
22        rref_val = self.expect_var_path("r_ref", type="TTT &&")
23        self.assertEqual(rref_val.Dereference().GetType().GetName(), "TTT")
24
25        # Typedef to a reference should dereference to the underlying type.
26        td_val = self.expect_var_path("td_to_ref_type", type="td_int_ref")
27        self.assertEqual(td_val.Dereference().GetType().GetName(), "int")
28