1 |
227 |
jeremybenn |
# 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 .
|
16 |
|
|
|
17 |
|
|
# This file is part of the gdb testsuite
|
18 |
|
|
|
19 |
|
|
# tests relating to ambiguous class members
|
20 |
|
|
# Written by Satish Pai 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 |
|
|
set prms_id 0
|
33 |
|
|
set bug_id 0
|
34 |
|
|
|
35 |
|
|
if { [skip_cplus_tests] } { continue }
|
36 |
|
|
|
37 |
|
|
set testfile "ambiguous"
|
38 |
|
|
set srcfile ${testfile}.cc
|
39 |
|
|
set binfile ${objdir}/${subdir}/${testfile}
|
40 |
|
|
|
41 |
|
|
if [get_compiler_info ${binfile} "c++"] {
|
42 |
|
|
return -1;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
if { [test_compiler_info gcc-*] } then { continue }
|
46 |
|
|
|
47 |
|
|
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
|
48 |
|
|
untested ambiguous.exp
|
49 |
|
|
return -1
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
gdb_exit
|
54 |
|
|
gdb_start
|
55 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
56 |
|
|
gdb_load ${binfile}
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
#
|
60 |
|
|
# set it up at a breakpoint so we can play with the variable values
|
61 |
|
|
#
|
62 |
|
|
if ![runto_main] then {
|
63 |
|
|
perror "couldn't run to breakpoint"
|
64 |
|
|
continue
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
send_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'
|
86 |
|
|
send_gdb "print x.x\n"
|
87 |
|
|
gdb_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'.
|
101 |
|
|
send_gdb "print n.x\n"
|
102 |
|
|
gdb_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.
|
114 |
|
|
send_gdb "print j.x\n"
|
115 |
|
|
gdb_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.
|
128 |
|
|
send_gdb "print jv.x\n"
|
129 |
|
|
gdb_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.
|
141 |
|
|
send_gdb "print jva1.x\n"
|
142 |
|
|
gdb_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'.
|
156 |
|
|
send_gdb "print jva2.x\n"
|
157 |
|
|
gdb_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.
|
171 |
|
|
send_gdb "print jva1v.x\n"
|
172 |
|
|
gdb_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.
|
185 |
|
|
send_gdb "print (A1)j\n"
|
186 |
|
|
gdb_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.
|
199 |
|
|
send_gdb "print (A1)jv\n"
|
200 |
|
|
gdb_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.
|
211 |
|
|
send_gdb "print (A1)jva1\n"
|
212 |
|
|
gdb_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.
|
225 |
|
|
send_gdb "print (A1)jva1v\n"
|
226 |
|
|
gdb_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 |
|
|
|