]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/nsusing.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / nsusing.exp
CommitLineData
1d506c26 1# Copyright 2008-2024 Free Software Foundation, Inc.
27aa8d6a
SW
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
f5f3a911 16standard_testfile .cc
27aa8d6a 17
5b362f04 18if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
f5f3a911
TT
19 return -1
20}
27aa8d6a
SW
21
22############################################
ac45a6ca 23# Test printing of namespace imported within the function.
27aa8d6a 24
95701cae 25if {![runto_main]} {
27aa8d6a
SW
26 continue
27}
28
29gdb_test "print _a" "= 1"
30
31############################################
ac45a6ca 32# Test printing of namespace imported into a scope containing the pc.
df83a9bf 33
27aa8d6a
SW
34gdb_breakpoint [gdb_get_line_number "marker1 stop"]
35gdb_continue_to_breakpoint "marker1 stop"
36
37gdb_test "print _a" "= 1" "print _a in a nested scope"
38
df83a9bf 39############################################
ac45a6ca 40# Test printing of namespace aliases.
df83a9bf 41
ac45a6ca
AB
42gdb_breakpoint marker2
43gdb_continue_to_breakpoint "marker2"
27aa8d6a 44
df83a9bf
SW
45gdb_test "print B::_a" "= 1"
46
df83a9bf
SW
47gdb_test "print _a" "No symbol \"_a\" in current context." \
48 "print _a in namespace alias scope"
49
df83a9bf
SW
50gdb_test "print x" "No symbol \"x\" in current context." \
51 "print x in namespace alias scope"
52
27aa8d6a 53############################################
df83a9bf 54# Test that names are not printed when they
ac45a6ca 55# are not imported.
27aa8d6a 56
ac45a6ca
AB
57gdb_breakpoint marker3
58gdb_continue_to_breakpoint "marker3"
27aa8d6a 59
8540c487
SW
60# gcc-4-3 puts import statements for aliases in
61# the global scope instead of the corresponding
62# function scope. These wrong import statements throw
63# this test off. This is fixed in gcc-4-4.
95701cae 64if {[test_compiler_info gcc-4-3-*]} { setup_xfail *-*-* }
8540c487 65
df83a9bf 66gdb_test "print _a" "No symbol \"_a\" in current context." \
ac45a6ca 67 "Print _a without import at marker3"
27aa8d6a
SW
68
69############################################
ac45a6ca 70# Test printing of individually imported elements.
27aa8d6a 71
ac45a6ca
AB
72gdb_breakpoint marker4
73gdb_continue_to_breakpoint "marker4"
13387711 74
df83a9bf 75gdb_test "print dx" "= 4"
8540c487
SW
76
77############################################
ac45a6ca 78# Test printing of namespace imported into file scope.
8540c487 79
ac45a6ca
AB
80gdb_breakpoint marker5
81gdb_continue_to_breakpoint "marker5"
82
83gdb_test "print cc" "= 3"
84
85# Also test printing of namespace aliases
8540c487 86
df83a9bf 87gdb_test "print efx" "= 5"
8540c487
SW
88
89############################################
ac45a6ca 90# Test printing of variables imported from nested namespaces.
df83a9bf 91
ac45a6ca
AB
92gdb_breakpoint I::marker7
93gdb_continue_to_breakpoint "I::marker7"
df83a9bf
SW
94
95gdb_test "print ghx" "= 6"
96
97############################################
ac45a6ca
AB
98# Test that variables are not printed in a namespace that is sibling
99# to the namespace containing an import.
df83a9bf 100
ac45a6ca
AB
101gdb_breakpoint L::marker8
102gdb_continue_to_breakpoint "L::marker8"
df83a9bf 103
ac45a6ca
AB
104gdb_test "print jx" "= 44" \
105 "print jx when the symbol is available"
df83a9bf
SW
106
107gdb_breakpoint "K::marker9"
108gdb_continue_to_breakpoint "K::marker9"
109
ac45a6ca
AB
110gdb_test "print jx" "No symbol \"jx\" in current context." \
111 "print jx when the symbol is not available"
8540c487 112
df83a9bf 113############################################
ac45a6ca
AB
114# Test that variables are only printed after the line containing the
115# import.
8540c487 116
df83a9bf
SW
117gdb_breakpoint [gdb_get_line_number "marker10 stop"]
118gdb_continue_to_breakpoint "marker10 stop"
119
1da644f0
SW
120if { [test_compiler_info {gcc-[0-3]-*}] ||
121 [test_compiler_info {gcc-4-[0-3]-*}]} {
68ce1575 122 return
1da644f0
SW
123}
124
0789a13f
TV
125# Xfail for incorrect decl_line on DW_TAG_imported_module,
126# gcc PR debug/108716.
127set have_gcc108716_xfail \
128 [expr [test_compiler_info gcc-*] && [gcc_major_version] < 13]
129
68ce1575
BL
130gdb_test_multiple "print x" "print x, before using statement" {
131 -re -wrap "No symbol .x. in current context.*" {
132 pass $gdb_test_name
133 }
bb391cb2 134 -re -wrap "Reference to .x. is ambiguous.*" {
0789a13f
TV
135 if { $have_gcc108716_xfail } {
136 # GCC doesn't properly set the decl_line for namespaces, so GDB
137 # believes that the "using namespace M" line has already passed at
138 # this point.
139 setup_xfail *-*-* gcc/108716
140 }
141 fail $gdb_test_name
68ce1575
BL
142 }
143}
144gdb_test "next" ".*" "using namespace M"
bb391cb2
BL
145gdb_test_multiple "print x" "print x, only using M" {
146 -re -wrap "= 911.*" {
147 pass $gdb_test_name
148 }
149 -re -wrap "Reference to .x. is ambiguous.*" {
0789a13f
TV
150 if { $have_gcc108716_xfail } {
151 setup_xfail *-*-* gcc/108716
152 }
153 fail $gdb_test_name
bb391cb2
BL
154 }
155}
156gdb_test "next" ".*" "using namespace N"
157gdb_test "print x" "Reference to .x. is ambiguous.*" "print x, with M and N"