1 # Copyright 1998-1999, 2003-2004, 2007-2012 Free Software Foundation,
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
25 # test running programs
29 if { [skip_cplus_tests] } { continue }
31 set testfile "ambiguous"
32 set srcfile ${testfile}.cc
33 set binfile ${objdir}/${subdir}/${testfile}
35 if [get_compiler_info ${binfile} "c++"] {
39 if { [test_compiler_info gcc-*] } then { continue }
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
42 untested ambiguous.exp
49 gdb_reinitialize_dir $srcdir/$subdir
54 # set it up at a breakpoint so we can play with the variable values
56 if ![runto_main] then {
57 perror "couldn't run to breakpoint"
61 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
64 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
67 -re ".*$gdb_prompt $" { pass "up from marker1" }
68 timeout { fail "up from marker1" }
71 -re "$gdb_prompt $" { fail "continue to marker1" }
72 timeout { fail "(timeout) continue to marker1" }
75 # print out various class objects' members. The values aren't
76 # important, just check that the warning is emitted at the
79 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
80 send_gdb "print x.x\n"
82 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
85 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
88 -re ".*$gdb_prompt $" { fail "print x.x" }
89 timeout { fail "(timeout) print x.x" }
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"
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 $" {
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 $" {
103 -re ".*$gdb_prompt $" { fail "print n.x" }
104 timeout { fail "(timeout) print n.x" }
107 # J is derived from A1 twice. A1 has a member x.
108 send_gdb "print j.x\n"
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 $" {
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 $" {
116 -re ".*$gdb_prompt $" { fail "print j.x" }
117 timeout { fail "(timeout) print j.x" }
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"
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)"
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" }
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
135 send_gdb "print jva1.x\n"
137 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
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 $" {
143 -re ".*$gdb_prompt $" { fail "print jva1.x" }
144 timeout { fail "(timeout) print jva1.x" }
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"
152 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
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 $" {
158 -re ".*$gdb_prompt $" { fail "print jva2.x" }
159 timeout { fail "(timeout) print jva2.x" }
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
165 send_gdb "print jva1v.x\n"
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)"
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" }
175 # Now check for ambiguous bases.
177 # J is derived from A1 twice; report ambiguity if a J is
179 send_gdb "print (A1)j\n"
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 $" {
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 $" {
187 -re ".*$gdb_prompt $" { fail "print (A1)j" }
188 timeout { fail "(timeout) print (A1)j" }
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"
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)"
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" }
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"
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"
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"
213 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
214 timeout { fail "(timeout) print (A1)jva1" }
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"
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)"
224 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
226 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
227 timeout { fail "(timeout) print (A1)jva1v" }