xref: /llvm-project/lldb/test/API/lang/cpp/function-ref-qualifiers/TestCppFunctionRefQualifiers.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
1"""
2Tests that C++ expression evaluation can
3disambiguate between rvalue and lvalue
4reference-qualified functions.
5"""
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class TestFunctionRefQualifiers(TestBase):
14    def test(self):
15        self.build()
16        lldbutil.run_to_source_breakpoint(
17            self, "Break here", lldb.SBFileSpec("main.cpp")
18        )
19
20        # const lvalue
21        self.expect_expr("const_foo.func()", result_type="uint32_t", result_value="0")
22
23        # const rvalue
24        self.expect_expr(
25            "static_cast<Foo const&&>(Foo{}).func()",
26            result_type="int64_t",
27            result_value="1",
28        )
29
30        # non-const lvalue
31        self.expect_expr("foo.func()", result_type="uint32_t", result_value="2")
32
33        # non-const rvalue
34        self.expect_expr("Foo{}.func()", result_type="int64_t", result_value="3")
35
36        self.filecheck("target modules dump ast", __file__)
37        # CHECK:      |-CXXMethodDecl {{.*}} func 'uint32_t () const &'
38        # CHECK-NEXT: | `-AsmLabelAttr {{.*}}
39        # CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'int64_t () const &&'
40        # CHECK-NEXT: | `-AsmLabelAttr {{.*}}
41        # CHECK-NEXT: |-CXXMethodDecl {{.*}} func 'uint32_t () &'
42        # CHECK-NEXT: | `-AsmLabelAttr {{.*}}
43        # CHECK-NEXT: `-CXXMethodDecl {{.*}} func 'int64_t () &&'
44        # CHECK-NEXT:   `-AsmLabelAttr {{.*}}
45