199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest that we correctly handle inline namespaces. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprechtimport lldb 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprechtclass TestInlineNamespace(TestBase): 1399451b44SJordan Rupprecht def test(self): 1499451b44SJordan Rupprecht self.build() 1599451b44SJordan Rupprecht 16*2238dcc3SJonas Devlieghere lldbutil.run_to_source_breakpoint( 17*2238dcc3SJonas Devlieghere self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp") 18*2238dcc3SJonas Devlieghere ) 1999451b44SJordan Rupprecht 2099451b44SJordan Rupprecht # The 'A::B::f' function must be found via 'A::f' as 'B' is an inline 2199451b44SJordan Rupprecht # namespace. 2299451b44SJordan Rupprecht self.expect_expr("A::f()", result_type="int", result_value="3") 2399451b44SJordan Rupprecht # But we should still find the function when we pretend the inline 2499451b44SJordan Rupprecht # namespace is not inline. 2599451b44SJordan Rupprecht self.expect_expr("A::B::f()", result_type="int", result_value="3") 26f8c9b30eSMichael Buch 27f8c9b30eSMichael Buch self.expect_expr("A::B::global_var", result_type="int", result_value="0") 28f8c9b30eSMichael Buch # FIXME: should be ambiguous lookup but ClangExpressionDeclMap takes 29f8c9b30eSMichael Buch # first global variable that the lookup found, which in this case 30f8c9b30eSMichael Buch # is A::B::global_var 31f8c9b30eSMichael Buch self.expect_expr("A::global_var", result_type="int", result_value="0") 32f8c9b30eSMichael Buch 33f8c9b30eSMichael Buch self.expect_expr("A::B::C::global_var", result_type="int", result_value="1") 34f8c9b30eSMichael Buch self.expect_expr("A::C::global_var", result_type="int", result_value="1") 35f8c9b30eSMichael Buch 36f8c9b30eSMichael Buch self.expect_expr("A::B::D::nested_var", result_type="int", result_value="2") 37f8c9b30eSMichael Buch self.expect_expr("A::D::nested_var", result_type="int", result_value="2") 38f8c9b30eSMichael Buch self.expect_expr("A::B::nested_var", result_type="int", result_value="2") 39f8c9b30eSMichael Buch self.expect_expr("A::nested_var", result_type="int", result_value="2") 40f8c9b30eSMichael Buch 41f8c9b30eSMichael Buch self.expect_expr("A::E::F::other_var", result_type="int", result_value="3") 42f8c9b30eSMichael Buch self.expect_expr("A::E::other_var", result_type="int", result_value="3") 43f8c9b30eSMichael Buch 44*2238dcc3SJonas Devlieghere self.expect( 45*2238dcc3SJonas Devlieghere "expr A::E::global_var", 46*2238dcc3SJonas Devlieghere error=True, 47*2238dcc3SJonas Devlieghere substrs=["no member named 'global_var' in namespace 'A::E'"], 48*2238dcc3SJonas Devlieghere ) 49*2238dcc3SJonas Devlieghere self.expect( 50*2238dcc3SJonas Devlieghere "expr A::E::F::global_var", 51*2238dcc3SJonas Devlieghere error=True, 52*2238dcc3SJonas Devlieghere substrs=["no member named 'global_var' in namespace 'A::E::F'"], 53*2238dcc3SJonas Devlieghere ) 54f8c9b30eSMichael Buch 55*2238dcc3SJonas Devlieghere self.expect( 56*2238dcc3SJonas Devlieghere "expr A::other_var", 57*2238dcc3SJonas Devlieghere error=True, 58*2238dcc3SJonas Devlieghere substrs=["no member named 'other_var' in namespace 'A'"], 59*2238dcc3SJonas Devlieghere ) 60*2238dcc3SJonas Devlieghere self.expect( 61*2238dcc3SJonas Devlieghere "expr A::B::other_var", 62*2238dcc3SJonas Devlieghere error=True, 63*2238dcc3SJonas Devlieghere substrs=["no member named 'other_var' in namespace 'A::B'"], 64*2238dcc3SJonas Devlieghere ) 65*2238dcc3SJonas Devlieghere self.expect( 66*2238dcc3SJonas Devlieghere "expr B::other_var", 67*2238dcc3SJonas Devlieghere error=True, 68*2238dcc3SJonas Devlieghere substrs=["no member named 'other_var' in namespace 'A::B'"], 69*2238dcc3SJonas Devlieghere ) 70f8c9b30eSMichael Buch 71f8c9b30eSMichael Buch # 'frame variable' can correctly distinguish between A::B::global_var and A::global_var 72f8c9b30eSMichael Buch gvars = self.target().FindGlobalVariables("A::global_var", 10) 73f8c9b30eSMichael Buch self.assertEqual(len(gvars), 1) 74f8c9b30eSMichael Buch self.assertEqual(gvars[0].GetValueAsSigned(), 4) 75f8c9b30eSMichael Buch 76f8c9b30eSMichael Buch self.expect("frame variable A::global_var", substrs=["(int) A::global_var = 4"]) 77*2238dcc3SJonas Devlieghere self.expect( 78*2238dcc3SJonas Devlieghere "frame variable A::B::global_var", substrs=["(int) A::B::global_var = 0"] 79*2238dcc3SJonas Devlieghere ) 80