import gdb-19990422 snapshot
[deliverable/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 if { [skip_hp_tests] } then { continue }
39
40 set testfile "ambiguous"
41 set srcfile ${testfile}.cc
42 set binfile ${objdir}/${subdir}/${testfile}
43
44 if [get_compiler_info ${binfile} "c++"] {
45 return -1;
46 }
47
48 if { $gcc_compiled } then { continue }
49
50 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
51 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52 }
53
54
55 gdb_exit
56 gdb_start
57 gdb_reinitialize_dir $srcdir/$subdir
58 gdb_load ${binfile}
59
60
61 #
62 # set it up at a breakpoint so we can play with the variable values
63 #
64 if ![runto_main] then {
65 perror "couldn't run to breakpoint"
66 continue
67 }
68
69 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
70 send_gdb "cont\n"
71 gdb_expect {
72 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
73 send_gdb "up\n"
74 gdb_expect {
75 -re ".*$gdb_prompt $" { pass "up from marker1" }
76 timeout { fail "up from marker1" }
77 }
78 }
79 -re "$gdb_prompt $" { fail "continue to marker1" }
80 timeout { fail "(timeout) continue to marker1" }
81 }
82
83 # print out various class objects' members. The values aren't
84 # important, just check that the warning is emitted at the
85 # right times.
86
87 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
88 send_gdb "print x.x\n"
89 gdb_expect {
90 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
91 pass "print x.x"
92 }
93 -re ".*$gdb_prompt $" { fail "print x.x" }
94 timeout { fail "(timeout) print x.x" }
95 }
96
97
98 # N is derived from A1 and A2, but not immediately -- two steps
99 # up in the hierarchy. Both A1 and A2 have a member 'x'.
100 send_gdb "print n.x\n"
101 gdb_expect {
102 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
103 pass "print n.x"
104 }
105 -re ".*$gdb_prompt $" { fail "print n.x" }
106 timeout { fail "(timeout) print n.x" }
107 }
108
109 # J is derived from A1 twice. A1 has a member x.
110 send_gdb "print j.x\n"
111 gdb_expect {
112 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
113 pass "print j.x"
114 }
115 -re ".*$gdb_prompt $" { fail "print j.x" }
116 timeout { fail "(timeout) print j.x" }
117 }
118
119 # JV is derived from A1 but A1 is a virtual base. Should not
120 # report an ambiguity in this case.
121 send_gdb "print jv.x\n"
122 gdb_expect {
123 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
124 fail "print jv.x (ambiguity reported)"
125 }
126 -re "\\$\[0-9\]* = 0\r\n$gdb_prompt $" { pass "print jv.x" }
127 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
128 timeout { fail "(timeout) print jv.x" }
129 }
130
131 # JVA1 is derived from A1; A1 occurs as a virtual base in two
132 # ancestors, and as a non-virtual immediate base. Ambiguity must
133 # be reported.
134 send_gdb "print jva1.x\n"
135 gdb_expect {
136 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
137 pass "print jva1.x"
138 }
139 -re ".*$gdb_prompt $" { fail "print jva1.x" }
140 timeout { fail "(timeout) print jva1.x" }
141 }
142
143 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
144 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
145 # be reported as A1 and A2 both have a member 'x'.
146 send_gdb "print jva2.x\n"
147 gdb_expect {
148 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
149 pass "print jva2.x"
150 }
151 -re ".*$gdb_prompt $" { fail "print jva2.x" }
152 timeout { fail "(timeout) print jva2.x" }
153 }
154
155 # JVA1V is derived from A1; A1 occurs as a virtual base in two
156 # ancestors, and also as a virtual immediate base. Ambiguity must
157 # not be reported.
158 send_gdb "print jva1v.x\n"
159 gdb_expect {
160 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = 0\r\n$gdb_prompt $" {
161 fail "print jva1v.x (ambiguity reported)"
162 }
163 -re "\\$\[0-9\]* = 0\r\n$gdb_prompt $" { pass "print jva1v.x" }
164 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
165 timeout { fail "(timeout) print jva1v.x" }
166 }
167
168 # Now check for ambiguous bases.
169
170 # J is derived from A1 twice; report ambiguity if a J is
171 # cast to an A1.
172 send_gdb "print (A1)j\n"
173 gdb_expect {
174 -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 $" {
175 pass "print (A1)j"
176 }
177 -re ".*$gdb_prompt $" { fail "print (A1)j" }
178 timeout { fail "(timeout) print (A1)j" }
179 }
180
181 # JV is derived from A1 twice, but A1 is a virtual base; should
182 # not report ambiguity when a JV is cast to an A1.
183 send_gdb "print (A1)jv\n"
184 gdb_expect {
185 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" {
186 fail "print (A1)jv (ambiguity reported)"
187 }
188 -re "\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
189 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
190 timeout { fail "(timeout) print (A1)jv" }
191 }
192
193 # JVA1 is derived from A1; A1 is a virtual base and also a
194 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
195 send_gdb "print (A1)jva1\n"
196 gdb_expect {
197 -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 $" {
198 pass "print (A1)jva1"
199 }
200 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
201 timeout { fail "(timeout) print (A1)jva1" }
202 }
203
204 # JVA1V is derived from A1; A1 is a virtual base indirectly
205 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
206 send_gdb "print (A1)jva1v\n"
207 gdb_expect {
208 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" {
209 fail "print (A1)jva1v (ambiguity reported)"
210 }
211 -re "\\$\[0-9\]* = \{x = 0, y = 0\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
212 }
213 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
214 timeout { fail "(timeout) print (A1)jva1v" }
215 }
216
217
This page took 0.037599 seconds and 4 git commands to generate.