199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest importing the 'std' C++ module and evaluate expressions with it. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 899451b44SJordan Rupprecht 999451b44SJordan Rupprecht 1099451b44SJordan Rupprechtclass ImportStdModule(TestBase): 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprecht @add_test_categories(["libc++"]) 1399451b44SJordan Rupprecht @skipIf(compiler=no_match("clang")) 1499451b44SJordan Rupprecht def test(self): 1599451b44SJordan Rupprecht self.build() 1699451b44SJordan Rupprecht 1799451b44SJordan Rupprecht lldbutil.run_to_source_breakpoint(self, 18cabee89bSRaphael Isemann "// Set break point at this line.", 19cabee89bSRaphael Isemann lldb.SBFileSpec("main.cpp")) 2099451b44SJordan Rupprecht 2199451b44SJordan Rupprecht # Activate importing of std module. 2299451b44SJordan Rupprecht self.runCmd("settings set target.import-std-module true") 2399451b44SJordan Rupprecht # Calling some normal std functions that return non-template types. 2499451b44SJordan Rupprecht self.expect_expr("std::abs(-42)", result_type="int", result_value="42") 25*f939a32eSRaphael Isemann self.expect_expr("std::minmax<int>(1, 2).first", result_type="const int", 26*f939a32eSRaphael Isemann result_value="1") 27cabee89bSRaphael Isemann self.expect_expr("std::div(2, 1).quot", 28cabee89bSRaphael Isemann result_type="int", 29cabee89bSRaphael Isemann result_value="2") 3099451b44SJordan Rupprecht # Using types from std. 31cabee89bSRaphael Isemann self.expect_expr("(std::size_t)33U", 32cabee89bSRaphael Isemann result_type="std::size_t", 33cabee89bSRaphael Isemann result_value="33") 3499451b44SJordan Rupprecht # Calling templated functions that return non-template types. 35cabee89bSRaphael Isemann self.expect_expr( 36cabee89bSRaphael Isemann "char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a", 37cabee89bSRaphael Isemann result_type="char", 38cabee89bSRaphael Isemann result_value="'a'") 3999451b44SJordan Rupprecht 4099451b44SJordan Rupprecht @add_test_categories(["libc++"]) 4199451b44SJordan Rupprecht @skipIf(compiler=no_match("clang")) 4299451b44SJordan Rupprecht def test_non_cpp_language(self): 4399451b44SJordan Rupprecht self.build() 4499451b44SJordan Rupprecht 4599451b44SJordan Rupprecht lldbutil.run_to_source_breakpoint(self, 46cabee89bSRaphael Isemann "// Set break point at this line.", 47cabee89bSRaphael Isemann lldb.SBFileSpec("main.cpp")) 4899451b44SJordan Rupprecht 4999451b44SJordan Rupprecht # Activate importing of std module. 5099451b44SJordan Rupprecht self.runCmd("settings set target.import-std-module true") 5199451b44SJordan Rupprecht # These languages don't support C++ modules, so they shouldn't 5299451b44SJordan Rupprecht # be able to evaluate the expression. 53*f939a32eSRaphael Isemann self.expect("expr -l C -- std::minmax<int>(1, 2).first", error=True) 54*f939a32eSRaphael Isemann self.expect("expr -l C99 -- std::minmax<int>(1, 2).first", error=True) 55*f939a32eSRaphael Isemann self.expect("expr -l C11 -- std::minmax<int>(1, 2).first", error=True) 56*f939a32eSRaphael Isemann self.expect("expr -l ObjC -- std::minmax<int>(1, 2).first", error=True) 57