]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/ambiguous.exp
dc4c2bef2276b6478c50eabbf77b23969a9ef593
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / ambiguous.exp
1 # Copyright 1998, 1999, 2003, 2004, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 # This file is part of the gdb testsuite
18
19 # tests relating to ambiguous class members
20 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-28
21
22 # This file is part of the gdb testsuite
23
24 if $tracelevel then {
25 strace $tracelevel
26 }
27
28 #
29 # test running programs
30 #
31
32
33 if { [skip_cplus_tests] } { continue }
34
35 set testfile "ambiguous"
36 set srcfile ${testfile}.cc
37 set binfile ${objdir}/${subdir}/${testfile}
38
39 if [get_compiler_info ${binfile} "c++"] {
40 return -1;
41 }
42
43 if { [test_compiler_info gcc-*] } then { continue }
44
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
46 untested ambiguous.exp
47 return -1
48 }
49
50
51 gdb_exit
52 gdb_start
53 gdb_reinitialize_dir $srcdir/$subdir
54 gdb_load ${binfile}
55
56
57 #
58 # set it up at a breakpoint so we can play with the variable values
59 #
60 if ![runto_main] then {
61 perror "couldn't run to breakpoint"
62 continue
63 }
64
65 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
66 send_gdb "cont\n"
67 gdb_expect {
68 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
69 send_gdb "up\n"
70 gdb_expect {
71 -re ".*$gdb_prompt $" { pass "up from marker1" }
72 timeout { fail "up from marker1" }
73 }
74 }
75 -re "$gdb_prompt $" { fail "continue to marker1" }
76 timeout { fail "(timeout) continue to marker1" }
77 }
78
79 # print out various class objects' members. The values aren't
80 # important, just check that the warning is emitted at the
81 # right times.
82
83 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
84 send_gdb "print x.x\n"
85 gdb_expect {
86 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
87 pass "print x.x"
88 }
89 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
90 pass "print x.x"
91 }
92 -re ".*$gdb_prompt $" { fail "print x.x" }
93 timeout { fail "(timeout) print x.x" }
94 }
95
96
97 # N is derived from A1 and A2, but not immediately -- two steps
98 # up in the hierarchy. Both A1 and A2 have a member 'x'.
99 send_gdb "print n.x\n"
100 gdb_expect {
101 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
102 pass "print n.x"
103 }
104 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
105 pass "print n.x"
106 }
107 -re ".*$gdb_prompt $" { fail "print n.x" }
108 timeout { fail "(timeout) print n.x" }
109 }
110
111 # J is derived from A1 twice. A1 has a member x.
112 send_gdb "print j.x\n"
113 gdb_expect {
114 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
115 pass "print j.x"
116 }
117 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
118 pass "print j.x"
119 }
120 -re ".*$gdb_prompt $" { fail "print j.x" }
121 timeout { fail "(timeout) print j.x" }
122 }
123
124 # JV is derived from A1 but A1 is a virtual base. Should not
125 # report an ambiguity in this case.
126 send_gdb "print jv.x\n"
127 gdb_expect {
128 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
129 fail "print jv.x (ambiguity reported)"
130 }
131 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
132 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
133 timeout { fail "(timeout) print jv.x" }
134 }
135
136 # JVA1 is derived from A1; A1 occurs as a virtual base in two
137 # ancestors, and as a non-virtual immediate base. Ambiguity must
138 # be reported.
139 send_gdb "print jva1.x\n"
140 gdb_expect {
141 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
142 pass "print jva1.x"
143 }
144 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
145 pass "print jva1.x"
146 }
147 -re ".*$gdb_prompt $" { fail "print jva1.x" }
148 timeout { fail "(timeout) print jva1.x" }
149 }
150
151 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
152 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
153 # be reported as A1 and A2 both have a member 'x'.
154 send_gdb "print jva2.x\n"
155 gdb_expect {
156 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
157 pass "print jva2.x"
158 }
159 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
160 pass "print jva2.x"
161 }
162 -re ".*$gdb_prompt $" { fail "print jva2.x" }
163 timeout { fail "(timeout) print jva2.x" }
164 }
165
166 # JVA1V is derived from A1; A1 occurs as a virtual base in two
167 # ancestors, and also as a virtual immediate base. Ambiguity must
168 # not be reported.
169 send_gdb "print jva1v.x\n"
170 gdb_expect {
171 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
172 fail "print jva1v.x (ambiguity reported)"
173 }
174 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
175 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
176 timeout { fail "(timeout) print jva1v.x" }
177 }
178
179 # Now check for ambiguous bases.
180
181 # J is derived from A1 twice; report ambiguity if a J is
182 # cast to an A1.
183 send_gdb "print (A1)j\n"
184 gdb_expect {
185 -re "warning: A1 ambiguous; using J::L::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
186 pass "print (A1)j"
187 }
188 -re "warning: A1 ambiguous; using J::K::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
189 pass "print (A1)j"
190 }
191 -re ".*$gdb_prompt $" { fail "print (A1)j" }
192 timeout { fail "(timeout) print (A1)j" }
193 }
194
195 # JV is derived from A1 twice, but A1 is a virtual base; should
196 # not report ambiguity when a JV is cast to an A1.
197 send_gdb "print (A1)jv\n"
198 gdb_expect {
199 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
200 fail "print (A1)jv (ambiguity reported)"
201 }
202 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
203 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
204 timeout { fail "(timeout) print (A1)jv" }
205 }
206
207 # JVA1 is derived from A1; A1 is a virtual base and also a
208 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
209 send_gdb "print (A1)jva1\n"
210 gdb_expect {
211 -re "warning: A1 ambiguous; using JVA1::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
212 pass "print (A1)jva1"
213 }
214 -re "warning: A1 ambiguous; using JVA1::KV::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
215 pass "print (A1)jva1"
216 }
217 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
218 timeout { fail "(timeout) print (A1)jva1" }
219 }
220
221 # JVA1V is derived from A1; A1 is a virtual base indirectly
222 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
223 send_gdb "print (A1)jva1v\n"
224 gdb_expect {
225 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
226 fail "print (A1)jva1v (ambiguity reported)"
227 }
228 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
229 }
230 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
231 timeout { fail "(timeout) print (A1)jva1v" }
232 }
233