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