1# Copyright 2008-2020 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 [get_compiler_info] {
23    return -1
24}
25
26if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
27    return -1
28}
29
30if ![runto_main] then {
31    perror "couldn't run to breakpoint main"
32    continue
33}
34
35############################################
36# Test printing of class variable is not shadowed
37# by global variable
38
39gdb_breakpoint [gdb_get_line_number "marker1"]
40gdb_continue_to_breakpoint "marker1"
41
42gdb_test "print x" "= 33" "print class x shadowing global x"
43
44
45############################################
46# Test printing local variable is not shadowed
47# by class variable
48
49gdb_breakpoint [gdb_get_line_number "marker2"]
50gdb_continue_to_breakpoint "marker2"
51
52gdb_test "print x" "= 44" "print local x shadowing class x"
53
54############################################
55# Test inner scope x is printed not outer scope
56
57gdb_breakpoint [gdb_get_line_number "marker3"]
58gdb_continue_to_breakpoint "marker3"
59
60gdb_test "print x" "= 55" "print inner scope x"
61
62############################################
63# Test printing local variable is not shadowed
64# by namespace variable
65
66gdb_breakpoint [gdb_get_line_number "marker4"]
67gdb_continue_to_breakpoint "marker4"
68
69gdb_test "print x" "= 55" "print local x not namespace x"
70
71############################################
72# Test imported namespace element is printed
73
74gdb_breakpoint [gdb_get_line_number "marker5"]
75gdb_continue_to_breakpoint "marker5"
76
77if { [test_compiler_info {gcc-[0-3]-*}] ||
78     [test_compiler_info {gcc-4-[0-3]-*}]} {
79    setup_xfail *-*-*
80}
81
82gdb_test "print x" "= 11" "print imported namespace x"
83