2 Test importing the 'std' C++ module and evaluate expressions with it.
5 from lldbsuite.test.decorators import *
6 from lldbsuite.test.lldbtest import *
7 from lldbsuite.test import lldbutil
10 class ImportStdModule(TestBase):
12 mydir = TestBase.compute_mydir(__file__)
14 @add_test_categories(["libc++"])
15 @skipIf(compiler=no_match("clang"))
19 lldbutil.run_to_source_breakpoint(self,
20 "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
22 # Activate importing of std module.
23 self.runCmd("settings set target.import-std-module true")
24 # Calling some normal std functions that return non-template types.
25 self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42'])
26 self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2'])
27 # Using types from std.
28 self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33'])
29 # Calling templated functions that return non-template types.
30 self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
31 substrs=["(char) $3 = 'a'"])
33 @add_test_categories(["libc++"])
34 @skipIf(compiler=no_match("clang"))
35 def test_non_cpp_language(self):
38 lldbutil.run_to_source_breakpoint(self,
39 "// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
41 # Activate importing of std module.
42 self.runCmd("settings set target.import-std-module true")
43 # These languages don't support C++ modules, so they shouldn't
44 # be able to evaluate the expression.
45 self.expect("expr -l C -- std::abs(-42)", error=True)
46 self.expect("expr -l C99 -- std::abs(-42)", error=True)
47 self.expect("expr -l C11 -- std::abs(-42)", error=True)
48 self.expect("expr -l ObjC -- std::abs(-42)", error=True)