xref: /llvm-project/lldb/test/API/lang/cpp/function-qualifiers/TestCppFunctionQualifiers.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprechtimport lldb
299451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
399451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
499451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
7*2238dcc3SJonas Devlieghereclass TestFunctionQualifiers(TestBase):
899451b44SJordan Rupprecht    def test(self):
999451b44SJordan Rupprecht        self.build()
10*2238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
11*2238dcc3SJonas Devlieghere            self, "// break here", lldb.SBFileSpec("main.cpp")
12*2238dcc3SJonas Devlieghere        )
1399451b44SJordan Rupprecht
1499451b44SJordan Rupprecht        # Test calling a function that has const/non-const overload.
1599451b44SJordan Rupprecht        self.expect_expr("c.func()", result_type="int", result_value="111")
1699451b44SJordan Rupprecht        self.expect_expr("const_c.func()", result_type="int", result_value="222")
1799451b44SJordan Rupprecht
1899451b44SJordan Rupprecht        # Call a function that is only const on a const/non-const instance.
1999451b44SJordan Rupprecht        self.expect_expr("c.const_func()", result_type="int", result_value="333")
2099451b44SJordan Rupprecht        self.expect_expr("const_c.const_func()", result_type="int", result_value="333")
2199451b44SJordan Rupprecht
2299451b44SJordan Rupprecht        # Call a function that is not const on a const/non-const instance.
2399451b44SJordan Rupprecht        self.expect_expr("c.nonconst_func()", result_type="int", result_value="444")
24*2238dcc3SJonas Devlieghere        self.expect(
25*2238dcc3SJonas Devlieghere            "expr const_c.nonconst_func()",
26*2238dcc3SJonas Devlieghere            error=True,
27*2238dcc3SJonas Devlieghere            substrs=[
28*2238dcc3SJonas Devlieghere                "'this' argument to member function 'nonconst_func' has type 'const C', but function is not marked const"
29*2238dcc3SJonas Devlieghere            ],
30*2238dcc3SJonas Devlieghere        )
31