1 # Copyright 1998, 1999, 2003, 2004 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 # This file is part of the gdb testsuite
19 # tests relating to ambiguous class members
20 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-28
22 # This file is part of the gdb testsuite
29 # test running programs
35 if { [skip_cplus_tests] } { continue }
37 set testfile "ambiguous"
38 set srcfile ${testfile}.cc
39 set binfile ${objdir}/${subdir}/${testfile}
41 if [get_compiler_info ${binfile} "c++"] {
45 if { [test_compiler_info gcc-*] } then { continue }
47 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
48 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
54 gdb_reinitialize_dir $srcdir/$subdir
59 # set it up at a breakpoint so we can play with the variable values
61 if ![runto_main] then {
62 perror "couldn't run to breakpoint"
66 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
69 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
72 -re ".*$gdb_prompt $" { pass "up from marker1" }
73 timeout { fail "up from marker1" }
76 -re "$gdb_prompt $" { fail "continue to marker1" }
77 timeout { fail "(timeout) continue to marker1" }
80 # print out various class objects' members. The values aren't
81 # important, just check that the warning is emitted at the
84 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
85 send_gdb "print x.x\n"
87 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
90 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
93 -re ".*$gdb_prompt $" { fail "print x.x" }
94 timeout { fail "(timeout) print x.x" }
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"
102 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
105 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
108 -re ".*$gdb_prompt $" { fail "print n.x" }
109 timeout { fail "(timeout) print n.x" }
112 # J is derived from A1 twice. A1 has a member x.
113 send_gdb "print j.x\n"
115 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
118 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
121 -re ".*$gdb_prompt $" { fail "print j.x" }
122 timeout { fail "(timeout) print j.x" }
125 # JV is derived from A1 but A1 is a virtual base. Should not
126 # report an ambiguity in this case.
127 send_gdb "print jv.x\n"
129 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
130 fail "print jv.x (ambiguity reported)"
132 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
133 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
134 timeout { fail "(timeout) print jv.x" }
137 # JVA1 is derived from A1; A1 occurs as a virtual base in two
138 # ancestors, and as a non-virtual immediate base. Ambiguity must
140 send_gdb "print jva1.x\n"
142 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
145 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
148 -re ".*$gdb_prompt $" { fail "print jva1.x" }
149 timeout { fail "(timeout) print jva1.x" }
152 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
153 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
154 # be reported as A1 and A2 both have a member 'x'.
155 send_gdb "print jva2.x\n"
157 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
160 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
163 -re ".*$gdb_prompt $" { fail "print jva2.x" }
164 timeout { fail "(timeout) print jva2.x" }
167 # JVA1V is derived from A1; A1 occurs as a virtual base in two
168 # ancestors, and also as a virtual immediate base. Ambiguity must
170 send_gdb "print jva1v.x\n"
172 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
173 fail "print jva1v.x (ambiguity reported)"
175 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
176 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
177 timeout { fail "(timeout) print jva1v.x" }
180 # Now check for ambiguous bases.
182 # J is derived from A1 twice; report ambiguity if a J is
184 send_gdb "print (A1)j\n"
186 -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 $" {
189 -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 $" {
192 -re ".*$gdb_prompt $" { fail "print (A1)j" }
193 timeout { fail "(timeout) print (A1)j" }
196 # JV is derived from A1 twice, but A1 is a virtual base; should
197 # not report ambiguity when a JV is cast to an A1.
198 send_gdb "print (A1)jv\n"
200 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
201 fail "print (A1)jv (ambiguity reported)"
203 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
204 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
205 timeout { fail "(timeout) print (A1)jv" }
208 # JVA1 is derived from A1; A1 is a virtual base and also a
209 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
210 send_gdb "print (A1)jva1\n"
212 -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 $" {
213 pass "print (A1)jva1"
215 -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 $" {
216 pass "print (A1)jva1"
218 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
219 timeout { fail "(timeout) print (A1)jva1" }
222 # JVA1V is derived from A1; A1 is a virtual base indirectly
223 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
224 send_gdb "print (A1)jva1v\n"
226 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
227 fail "print (A1)jva1v (ambiguity reported)"
229 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
231 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
232 timeout { fail "(timeout) print (A1)jva1v" }