* gdb.cp/abstract-origin.exp: Use standard_testfile.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / ambiguous.exp
1 # Copyright 1998-1999, 2003-2004, 2007-2012 Free Software Foundation,
2 # 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 #
25 # test running programs
26 #
27
28
29 if { [skip_cplus_tests] } { continue }
30
31 standard_testfile .cc
32
33 if [get_compiler_info "c++"] {
34 return -1;
35 }
36
37 if { [test_compiler_info gcc-*] } then { continue }
38
39 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
40 return -1
41 }
42
43 #
44 # set it up at a breakpoint so we can play with the variable values
45 #
46 if ![runto_main] then {
47 perror "couldn't run to breakpoint"
48 continue
49 }
50
51 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
52 send_gdb "cont\n"
53 gdb_expect {
54 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
55 send_gdb "up\n"
56 gdb_expect {
57 -re ".*$gdb_prompt $" { pass "up from marker1" }
58 timeout { fail "up from marker1" }
59 }
60 }
61 -re "$gdb_prompt $" { fail "continue to marker1" }
62 timeout { fail "(timeout) continue to marker1" }
63 }
64
65 # print out various class objects' members. The values aren't
66 # important, just check that the warning is emitted at the
67 # right times.
68
69 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
70 send_gdb "print x.x\n"
71 gdb_expect {
72 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
73 pass "print x.x"
74 }
75 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
76 pass "print x.x"
77 }
78 -re ".*$gdb_prompt $" { fail "print x.x" }
79 timeout { fail "(timeout) print x.x" }
80 }
81
82
83 # N is derived from A1 and A2, but not immediately -- two steps
84 # up in the hierarchy. Both A1 and A2 have a member 'x'.
85 send_gdb "print n.x\n"
86 gdb_expect {
87 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
88 pass "print n.x"
89 }
90 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
91 pass "print n.x"
92 }
93 -re ".*$gdb_prompt $" { fail "print n.x" }
94 timeout { fail "(timeout) print n.x" }
95 }
96
97 # J is derived from A1 twice. A1 has a member x.
98 send_gdb "print j.x\n"
99 gdb_expect {
100 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
101 pass "print j.x"
102 }
103 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
104 pass "print j.x"
105 }
106 -re ".*$gdb_prompt $" { fail "print j.x" }
107 timeout { fail "(timeout) print j.x" }
108 }
109
110 # JV is derived from A1 but A1 is a virtual base. Should not
111 # report an ambiguity in this case.
112 send_gdb "print jv.x\n"
113 gdb_expect {
114 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
115 fail "print jv.x (ambiguity reported)"
116 }
117 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
118 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
119 timeout { fail "(timeout) print jv.x" }
120 }
121
122 # JVA1 is derived from A1; A1 occurs as a virtual base in two
123 # ancestors, and as a non-virtual immediate base. Ambiguity must
124 # be reported.
125 send_gdb "print jva1.x\n"
126 gdb_expect {
127 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
128 pass "print jva1.x"
129 }
130 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
131 pass "print jva1.x"
132 }
133 -re ".*$gdb_prompt $" { fail "print jva1.x" }
134 timeout { fail "(timeout) print jva1.x" }
135 }
136
137 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
138 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
139 # be reported as A1 and A2 both have a member 'x'.
140 send_gdb "print jva2.x\n"
141 gdb_expect {
142 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
143 pass "print jva2.x"
144 }
145 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
146 pass "print jva2.x"
147 }
148 -re ".*$gdb_prompt $" { fail "print jva2.x" }
149 timeout { fail "(timeout) print jva2.x" }
150 }
151
152 # JVA1V is derived from A1; A1 occurs as a virtual base in two
153 # ancestors, and also as a virtual immediate base. Ambiguity must
154 # not be reported.
155 send_gdb "print jva1v.x\n"
156 gdb_expect {
157 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
158 fail "print jva1v.x (ambiguity reported)"
159 }
160 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
161 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
162 timeout { fail "(timeout) print jva1v.x" }
163 }
164
165 # Now check for ambiguous bases.
166
167 # J is derived from A1 twice; report ambiguity if a J is
168 # cast to an A1.
169 send_gdb "print (A1)j\n"
170 gdb_expect {
171 -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 $" {
172 pass "print (A1)j"
173 }
174 -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 $" {
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-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
186 fail "print (A1)jv (ambiguity reported)"
187 }
188 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\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::A1. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
198 pass "print (A1)jva1"
199 }
200 -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 $" {
201 pass "print (A1)jva1"
202 }
203 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
204 timeout { fail "(timeout) print (A1)jva1" }
205 }
206
207 # JVA1V is derived from A1; A1 is a virtual base indirectly
208 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
209 send_gdb "print (A1)jva1v\n"
210 gdb_expect {
211 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
212 fail "print (A1)jva1v (ambiguity reported)"
213 }
214 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
215 }
216 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
217 timeout { fail "(timeout) print (A1)jva1v" }
218 }
219
This page took 0.035358 seconds and 5 git commands to generate.