8939951ec4758d8ae50c4c99504c99f35079c4dd
[lldb.git] / lldb / test / API / lang / cpp / template-function / TestTemplateFunctions.py
1 """
2 Test that we can call C++ template fucntions.
3 """
4 import lldb
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
8
9
10 class TemplateFunctionsTestCase(TestBase):
11
12     mydir = TestBase.compute_mydir(__file__)
13
14     def do_test_template_function(self, add_cast):
15         self.build()
16         lldbutil.run_to_source_breakpoint(self, '// break here',
17                 lldb.SBFileSpec("main.cpp", False))
18
19         if add_cast:
20           self.expect_expr("(int) foo(42)", result_type="int", result_value="42")
21         else:
22           self.expect("expr b1 <=> b2",  error=True, substrs=["warning: <user expression 0>:1:4: '<=>' is a single token in C++20; add a space to avoid a change in behavior"])
23
24           self.expect_expr("foo(42)", result_type="int", result_value="42")
25
26           # overload with template case
27           self.expect_expr("h(10)", result_type="int", result_value="10")
28
29           # ADL lookup case
30           self.expect_expr("f(A::C{})", result_type="int", result_value="4")
31
32           # ADL lookup but no overload
33           self.expect_expr("g(A::C{})", result_type="int", result_value="4")
34
35           # variadic function cases
36           self.expect_expr("var(1)", result_type="int", result_value="10")
37           self.expect_expr("var(1, 2)", result_type="int", result_value="10")
38
39           # Overloaded templated operator case
40           self.expect_expr("b1 > b2", result_type="bool", result_value="true")
41           self.expect_expr("b1 >> b2", result_type="bool", result_value="true")
42           self.expect_expr("b1 << b2", result_type="bool", result_value="true")
43           self.expect_expr("b1 == b2", result_type="bool", result_value="true")
44
45           # Overloaded operator case
46           self.expect_expr("d1 > d2", result_type="bool", result_value="true")
47           self.expect_expr("d1 >> d2", result_type="bool", result_value="true")
48           self.expect_expr("d1 << d2", result_type="bool", result_value="true")
49           self.expect_expr("d1 == d2", result_type="bool", result_value="true")
50
51     @skipIfWindows
52     def test_template_function_with_cast(self):
53         self.do_test_template_function(True)
54
55     @skipIfWindows
56     @expectedFailureAll(debug_info=["dwarf", "gmodules", "dwo", "dts", "dwz"])
57     def test_template_function_without_cast(self):
58         self.do_test_template_function(False)