]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/ambiguous.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / ambiguous.exp
1 # Copyright (C) 1998 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 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
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file is part of the gdb testsuite
21
22 # tests relating to ambiguous class members
23 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-28
24
25 # This file is part of the gdb testsuite
26
27 if $tracelevel then {
28 strace $tracelevel
29 }
30
31 #
32 # test running programs
33 #
34
35 set prms_id 0
36 set bug_id 0
37
38 set testfile "ambiguous"
39 set srcfile ${testfile}.cc
40 set binfile ${objdir}/${subdir}/${testfile}
41
42 if [get_compiler_info ${binfile} "c++"] {
43 return -1;
44 }
45
46
47 if {[skip_hp_tests $gcc_compiled]} then { continue }
48
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 }
52
53
54 gdb_exit
55 gdb_start
56 gdb_reinitialize_dir $srcdir/$subdir
57 gdb_load ${binfile}
58
59
60 #
61 # set it up at a breakpoint so we can play with the variable values
62 #
63 if ![runto_main] then {
64 perror "couldn't run to breakpoint"
65 continue
66 }
67
68 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
69 send_gdb "cont\n"
70 gdb_expect {
71 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
72 send_gdb "up\n"
73 gdb_expect {
74 -re ".*$gdb_prompt $" { pass "up from marker1" }
75 timeout { fail "up from marker1" }
76 }
77 }
78 -re "$gdb_prompt $" { fail "continue to marker1" }
79 timeout { fail "(timeout) continue to marker1" }
80 }
81
82 # print out various class objects' members. The values aren't
83 # important, just check that the warning is emitted at the
84 # right times.
85
86 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
87 send_gdb "print x.x\n"
88 gdb_expect {
89 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\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::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
102 pass "print n.x"
103 }
104 -re ".*$gdb_prompt $" { fail "print n.x" }
105 timeout { fail "(timeout) print n.x" }
106 }
107
108 # J is derived from A1 twice. A1 has a member x.
109 send_gdb "print j.x\n"
110 gdb_expect {
111 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
112 pass "print j.x"
113 }
114 -re ".*$gdb_prompt $" { fail "print j.x" }
115 timeout { fail "(timeout) print j.x" }
116 }
117
118 # JV is derived from A1 but A1 is a virtual base. Should not
119 # report an ambiguity in this case.
120 send_gdb "print jv.x\n"
121 gdb_expect {
122 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
123 fail "print jv.x (ambiguity reported)"
124 }
125 -re "\\$\[0-9\]* = 0\r\n$gdb_prompt $" { pass "print jv.x" }
126 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
127 timeout { fail "(timeout) print jv.x" }
128 }
129
130 # JVA1 is derived from A1; A1 occurs as a virtual base in two
131 # ancestors, and as a non-virtual immediate base. Ambiguity must
132 # be reported.
133 send_gdb "print jva1.x\n"
134 gdb_expect {
135 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
136 pass "print jva1.x"
137 }
138 -re ".*$gdb_prompt $" { fail "print jva1.x" }
139 timeout { fail "(timeout) print jva1.x" }
140 }
141
142 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
143 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
144 # be reported as A1 and A2 both have a member 'x'.
145 send_gdb "print jva2.x\n"
146 gdb_expect {
147 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
148 pass "print jva2.x"
149 }
150 -re ".*$gdb_prompt $" { fail "print jva2.x" }
151 timeout { fail "(timeout) print jva2.x" }
152 }
153
154 # JVA1V is derived from A1; A1 occurs as a virtual base in two
155 # ancestors, and also as a virtual immediate base. Ambiguity must
156 # not be reported.
157 send_gdb "print jva1v.x\n"
158 gdb_expect {
159 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
160 fail "print jva1v.x (ambiguity reported)"
161 }
162 -re "\\$\[0-9\]* = 0\r\n$gdb_prompt $" { pass "print jva1v.x" }
163 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
164 timeout { fail "(timeout) print jva1v.x" }
165 }
166
167 # Now check for ambiguous bases.
168
169 # J is derived from A1 twice; report ambiguity if a J is
170 # cast to an A1.
171 send_gdb "print (A1)j\n"
172 gdb_expect {
173 -re "warning: A1 ambiguous; using J::K::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" {
174 pass "print (A1)j"
175 }
176 -re ".*$gdb_prompt $" { fail "print (A1)j" }
177 timeout { fail "(timeout) print (A1)j" }
178 }
179
180 # JV is derived from A1 twice, but A1 is a virtual base; should
181 # not report ambiguity when a JV is cast to an A1.
182 send_gdb "print (A1)jv\n"
183 gdb_expect {
184 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" {
185 fail "print (A1)jv (ambiguity reported)"
186 }
187 -re "\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
188 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
189 timeout { fail "(timeout) print (A1)jv" }
190 }
191
192 # JVA1 is derived from A1; A1 is a virtual base and also a
193 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
194 send_gdb "print (A1)jva1\n"
195 gdb_expect {
196 -re "warning: A1 ambiguous; using JVA1::KV::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" {
197 pass "print (A1)jva1"
198 }
199 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
200 timeout { fail "(timeout) print (A1)jva1" }
201 }
202
203 # JVA1V is derived from A1; A1 is a virtual base indirectly
204 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
205 send_gdb "print (A1)jva1v\n"
206 gdb_expect {
207 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" {
208 fail "print (A1)jva1v (ambiguity reported)"
209 }
210 -re "\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
211 }
212 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
213 timeout { fail "(timeout) print (A1)jva1v" }
214 }
215
216