1# Copyright 2008-2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Test that when multiple variables have the same
17# name the one from the correct scope is printed.
18
19
20standard_testfile .cc
21
22if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
23    return -1
24}
25
26if {![runto_main]} {
27    return
28}
29
30############################################
31# Test printing of class variable is not shadowed
32# by global variable
33
34gdb_breakpoint [gdb_get_line_number "marker1"]
35gdb_continue_to_breakpoint "marker1"
36
37gdb_test "print x" "= 33" "print class x shadowing global x"
38
39
40############################################
41# Test printing local variable is not shadowed
42# by class variable
43
44gdb_breakpoint [gdb_get_line_number "marker2"]
45gdb_continue_to_breakpoint "marker2"
46
47gdb_test "print x" "= 44" "print local x shadowing class x"
48
49############################################
50# Test inner scope x is printed not outer scope
51
52gdb_breakpoint [gdb_get_line_number "marker3"]
53gdb_continue_to_breakpoint "marker3"
54
55gdb_test "print x" "= 55" "print inner scope x"
56
57############################################
58# Test printing local variable is not shadowed
59# by namespace variable
60
61gdb_breakpoint [gdb_get_line_number "marker4"]
62gdb_continue_to_breakpoint "marker4"
63
64gdb_test "print x" "= 55" "print local x not namespace x"
65
66############################################
67# Test imported namespace element is printed
68
69gdb_breakpoint [gdb_get_line_number "marker5"]
70gdb_continue_to_breakpoint "marker5"
71
72if { [test_compiler_info {gcc-[0-3]-*}] ||
73     [test_compiler_info {gcc-4-[0-3]-*}]} {
74    setup_xfail *-*-*
75}
76
77gdb_test "print x" "= 11" "print imported namespace x"
78