1 # Copyright 2008-2020 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test that when multiple variables have the same
17 # name the one from the correct scope is printed.
22 if [get_compiler_info] {
26 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
30 if ![runto_main] then {
31 perror "couldn't run to breakpoint main"
35 ############################################
36 # Test printing of class variable is not shadowed
39 gdb_breakpoint [gdb_get_line_number "marker1"]
40 gdb_continue_to_breakpoint "marker1"
42 gdb_test "print x" "= 33" "print class x shadowing global x"
45 ############################################
46 # Test printing local variable is not shadowed
49 gdb_breakpoint [gdb_get_line_number "marker2"]
50 gdb_continue_to_breakpoint "marker2"
52 gdb_test "print x" "= 44" "print local x shadowing class x"
54 ############################################
55 # Test inner scope x is printed not outer scope
57 gdb_breakpoint [gdb_get_line_number "marker3"]
58 gdb_continue_to_breakpoint "marker3"
60 gdb_test "print x" "= 55" "print inner scope x"
62 ############################################
63 # Test printing local variable is not shadowed
64 # by namespace variable
66 gdb_breakpoint [gdb_get_line_number "marker4"]
67 gdb_continue_to_breakpoint "marker4"
69 gdb_test "print x" "= 55" "print local x not namespace x"
71 ############################################
72 # Test imported namespace element is printed
74 gdb_breakpoint [gdb_get_line_number "marker5"]
75 gdb_continue_to_breakpoint "marker5"
77 if { [test_compiler_info {gcc-[0-3]-*}] ||
78 [test_compiler_info {gcc-4-[0-3]-*}]} {
82 gdb_test "print x" "= 11" "print imported namespace x"