1 # Copyright 1998, 1999, 2003, 2004, 2007, 2008, 2009
2 # Free Software Foundation, Inc.
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.
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.
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/>.
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 untested ambiguous.exp
55 gdb_reinitialize_dir $srcdir/$subdir
60 # set it up at a breakpoint so we can play with the variable values
62 if ![runto_main] then {
63 perror "couldn't run to breakpoint"
67 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
70 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
73 -re ".*$gdb_prompt $" { pass "up from marker1" }
74 timeout { fail "up from marker1" }
77 -re "$gdb_prompt $" { fail "continue to marker1" }
78 timeout { fail "(timeout) continue to marker1" }
81 # print out various class objects' members. The values aren't
82 # important, just check that the warning is emitted at the
85 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
86 send_gdb "print x.x\n"
88 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
91 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
94 -re ".*$gdb_prompt $" { fail "print x.x" }
95 timeout { fail "(timeout) print x.x" }
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"
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 $" {
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 $" {
109 -re ".*$gdb_prompt $" { fail "print n.x" }
110 timeout { fail "(timeout) print n.x" }
113 # J is derived from A1 twice. A1 has a member x.
114 send_gdb "print j.x\n"
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 $" {
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 $" {
122 -re ".*$gdb_prompt $" { fail "print j.x" }
123 timeout { fail "(timeout) print j.x" }
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"
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)"
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" }
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
141 send_gdb "print jva1.x\n"
143 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
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 $" {
149 -re ".*$gdb_prompt $" { fail "print jva1.x" }
150 timeout { fail "(timeout) print jva1.x" }
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"
158 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
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 $" {
164 -re ".*$gdb_prompt $" { fail "print jva2.x" }
165 timeout { fail "(timeout) print jva2.x" }
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
171 send_gdb "print jva1v.x\n"
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)"
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" }
181 # Now check for ambiguous bases.
183 # J is derived from A1 twice; report ambiguity if a J is
185 send_gdb "print (A1)j\n"
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 $" {
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 $" {
193 -re ".*$gdb_prompt $" { fail "print (A1)j" }
194 timeout { fail "(timeout) print (A1)j" }
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"
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)"
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" }
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"
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"
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"
219 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
220 timeout { fail "(timeout) print (A1)jva1" }
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"
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)"
230 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
232 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
233 timeout { fail "(timeout) print (A1)jva1v" }