1 # Copyright 1998, 1999 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file is part of the gdb testsuite
22 # tests relating to ambiguous class members
23 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-28
25 # This file is part of the gdb testsuite
32 # test running programs
38 if { [skip_cplus_tests] } { continue }
40 set testfile "ambiguous"
41 set srcfile ${testfile}.cc
42 set binfile ${objdir}/${subdir}/${testfile}
44 if [get_compiler_info ${binfile} "c++"] {
48 if { $gcc_compiled } then { continue }
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."
57 gdb_reinitialize_dir $srcdir/$subdir
62 # set it up at a breakpoint so we can play with the variable values
64 if ![runto_main] then {
65 perror "couldn't run to breakpoint"
69 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
72 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
75 -re ".*$gdb_prompt $" { pass "up from marker1" }
76 timeout { fail "up from marker1" }
79 -re "$gdb_prompt $" { fail "continue to marker1" }
80 timeout { fail "(timeout) continue to marker1" }
83 # print out various class objects' members. The values aren't
84 # important, just check that the warning is emitted at the
87 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
88 send_gdb "print x.x\n"
90 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
93 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
96 -re ".*$gdb_prompt $" { fail "print x.x" }
97 timeout { fail "(timeout) print x.x" }
101 # N is derived from A1 and A2, but not immediately -- two steps
102 # up in the hierarchy. Both A1 and A2 have a member 'x'.
103 send_gdb "print n.x\n"
105 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
108 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
111 -re ".*$gdb_prompt $" { fail "print n.x" }
112 timeout { fail "(timeout) print n.x" }
115 # J is derived from A1 twice. A1 has a member x.
116 send_gdb "print j.x\n"
118 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
121 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
124 -re ".*$gdb_prompt $" { fail "print j.x" }
125 timeout { fail "(timeout) print j.x" }
128 # JV is derived from A1 but A1 is a virtual base. Should not
129 # report an ambiguity in this case.
130 send_gdb "print jv.x\n"
132 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
133 fail "print jv.x (ambiguity reported)"
135 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
136 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
137 timeout { fail "(timeout) print jv.x" }
140 # JVA1 is derived from A1; A1 occurs as a virtual base in two
141 # ancestors, and as a non-virtual immediate base. Ambiguity must
143 send_gdb "print jva1.x\n"
145 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
148 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
151 -re ".*$gdb_prompt $" { fail "print jva1.x" }
152 timeout { fail "(timeout) print jva1.x" }
155 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
156 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
157 # be reported as A1 and A2 both have a member 'x'.
158 send_gdb "print jva2.x\n"
160 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
163 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
166 -re ".*$gdb_prompt $" { fail "print jva2.x" }
167 timeout { fail "(timeout) print jva2.x" }
170 # JVA1V is derived from A1; A1 occurs as a virtual base in two
171 # ancestors, and also as a virtual immediate base. Ambiguity must
173 send_gdb "print jva1v.x\n"
175 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
176 fail "print jva1v.x (ambiguity reported)"
178 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
179 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
180 timeout { fail "(timeout) print jva1v.x" }
183 # Now check for ambiguous bases.
185 # J is derived from A1 twice; report ambiguity if a J is
187 send_gdb "print (A1)j\n"
189 -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 $" {
192 -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 $" {
195 -re ".*$gdb_prompt $" { fail "print (A1)j" }
196 timeout { fail "(timeout) print (A1)j" }
199 # JV is derived from A1 twice, but A1 is a virtual base; should
200 # not report ambiguity when a JV is cast to an A1.
201 send_gdb "print (A1)jv\n"
203 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
204 fail "print (A1)jv (ambiguity reported)"
206 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
207 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
208 timeout { fail "(timeout) print (A1)jv" }
211 # JVA1 is derived from A1; A1 is a virtual base and also a
212 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
213 send_gdb "print (A1)jva1\n"
215 -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 $" {
216 pass "print (A1)jva1"
218 -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 $" {
219 pass "print (A1)jva1"
221 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
222 timeout { fail "(timeout) print (A1)jva1" }
225 # JVA1V is derived from A1; A1 is a virtual base indirectly
226 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
227 send_gdb "print (A1)jva1v\n"
229 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
230 fail "print (A1)jva1v (ambiguity reported)"
232 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
234 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
235 timeout { fail "(timeout) print (A1)jva1v" }