]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.cp/ambiguous.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / ambiguous.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2003, 2004, 2007 Free Software Foundation, Inc.
a0b3c4fd
JM
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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
a0b3c4fd
JM
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
24if $tracelevel then {
25 strace $tracelevel
26 }
27
28#
29# test running programs
30#
31
32set prms_id 0
33set bug_id 0
34
d4f3574e
SS
35if { [skip_cplus_tests] } { continue }
36
a0b3c4fd
JM
37set testfile "ambiguous"
38set srcfile ${testfile}.cc
39set binfile ${objdir}/${subdir}/${testfile}
40
41if [get_compiler_info ${binfile} "c++"] {
42 return -1;
43}
44
4d9eda44 45if { [test_compiler_info gcc-*] } then { continue }
a0b3c4fd
JM
46
47if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
48 untested ambiguous.exp
49 return -1
a0b3c4fd
JM
50}
51
52
53gdb_exit
54gdb_start
55gdb_reinitialize_dir $srcdir/$subdir
56gdb_load ${binfile}
57
58
59#
60# set it up at a breakpoint so we can play with the variable values
61#
62if ![runto_main] then {
63 perror "couldn't run to breakpoint"
64 continue
65}
66
67send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
68 send_gdb "cont\n"
69 gdb_expect {
70 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
71 send_gdb "up\n"
72 gdb_expect {
73 -re ".*$gdb_prompt $" { pass "up from marker1" }
74 timeout { fail "up from marker1" }
75 }
76 }
77 -re "$gdb_prompt $" { fail "continue to marker1" }
78 timeout { fail "(timeout) continue to marker1" }
79 }
80
81# print out various class objects' members. The values aren't
82# important, just check that the warning is emitted at the
83# right times.
84
85# X is derived from A1 and A2; both A1 and A2 have a member 'x'
86send_gdb "print x.x\n"
87gdb_expect {
88 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
89 pass "print x.x"
90 }
91 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
92 pass "print x.x"
93 }
94 -re ".*$gdb_prompt $" { fail "print x.x" }
95 timeout { fail "(timeout) print x.x" }
96}
97
98
99# N is derived from A1 and A2, but not immediately -- two steps
100# up in the hierarchy. Both A1 and A2 have a member 'x'.
101send_gdb "print n.x\n"
102gdb_expect {
103 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
104 pass "print n.x"
105 }
106 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
107 pass "print n.x"
108 }
109 -re ".*$gdb_prompt $" { fail "print n.x" }
110 timeout { fail "(timeout) print n.x" }
111}
112
113# J is derived from A1 twice. A1 has a member x.
114send_gdb "print j.x\n"
115gdb_expect {
116 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
117 pass "print j.x"
118 }
119 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
120 pass "print j.x"
121 }
122 -re ".*$gdb_prompt $" { fail "print j.x" }
123 timeout { fail "(timeout) print j.x" }
124}
125
126# JV is derived from A1 but A1 is a virtual base. Should not
127# report an ambiguity in this case.
128send_gdb "print jv.x\n"
129gdb_expect {
130 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
131 fail "print jv.x (ambiguity reported)"
132 }
133 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
134 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
135 timeout { fail "(timeout) print jv.x" }
136}
137
138# JVA1 is derived from A1; A1 occurs as a virtual base in two
139# ancestors, and as a non-virtual immediate base. Ambiguity must
140# be reported.
141send_gdb "print jva1.x\n"
142gdb_expect {
143 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
144 pass "print jva1.x"
145 }
146 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
147 pass "print jva1.x"
148 }
149 -re ".*$gdb_prompt $" { fail "print jva1.x" }
150 timeout { fail "(timeout) print jva1.x" }
151}
152
153# JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
154# ancestors, and A2 is a non-virtual immediate base. Ambiguity must
155# be reported as A1 and A2 both have a member 'x'.
156send_gdb "print jva2.x\n"
157gdb_expect {
158 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
159 pass "print jva2.x"
160 }
161 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
162 pass "print jva2.x"
163 }
164 -re ".*$gdb_prompt $" { fail "print jva2.x" }
165 timeout { fail "(timeout) print jva2.x" }
166}
167
168# JVA1V is derived from A1; A1 occurs as a virtual base in two
169# ancestors, and also as a virtual immediate base. Ambiguity must
170# not be reported.
171send_gdb "print jva1v.x\n"
172gdb_expect {
173 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
174 fail "print jva1v.x (ambiguity reported)"
175 }
176 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
177 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
178 timeout { fail "(timeout) print jva1v.x" }
179}
180
181# Now check for ambiguous bases.
182
183# J is derived from A1 twice; report ambiguity if a J is
184# cast to an A1.
185send_gdb "print (A1)j\n"
186gdb_expect {
187 -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 $" {
188 pass "print (A1)j"
189 }
190 -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 $" {
191 pass "print (A1)j"
192 }
193 -re ".*$gdb_prompt $" { fail "print (A1)j" }
194 timeout { fail "(timeout) print (A1)j" }
195}
196
197# JV is derived from A1 twice, but A1 is a virtual base; should
198# not report ambiguity when a JV is cast to an A1.
199send_gdb "print (A1)jv\n"
200gdb_expect {
201 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
202 fail "print (A1)jv (ambiguity reported)"
203 }
204 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
205 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
206 timeout { fail "(timeout) print (A1)jv" }
207}
208
209# JVA1 is derived from A1; A1 is a virtual base and also a
210# non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
211send_gdb "print (A1)jva1\n"
212gdb_expect {
213 -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 $" {
214 pass "print (A1)jva1"
215 }
216 -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 $" {
217 pass "print (A1)jva1"
218 }
219 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
220 timeout { fail "(timeout) print (A1)jva1" }
221}
222
223# JVA1V is derived from A1; A1 is a virtual base indirectly
224# and also directly; must not report ambiguity when a JVA1V is cast to an A1.
225send_gdb "print (A1)jva1v\n"
226gdb_expect {
227 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
228 fail "print (A1)jva1v (ambiguity reported)"
229 }
230 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
231 }
232 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
233 timeout { fail "(timeout) print (A1)jva1v" }
234}
235