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 }
33 if [get_compiler_info "c++"] {
37 if { [test_compiler_info gcc-*] } then { continue }
39 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
44 # set it up at a breakpoint so we can play with the variable values
46 if ![runto_main] then {
47 perror "couldn't run to breakpoint"
51 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
54 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
57 -re ".*$gdb_prompt $" { pass "up from marker1" }
58 timeout { fail "up from marker1" }
61 -re "$gdb_prompt $" { fail "continue to marker1" }
62 timeout { fail "(timeout) continue to marker1" }
65 # print out various class objects' members. The values aren't
66 # important, just check that the warning is emitted at the
69 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
70 send_gdb "print x.x\n"
72 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
75 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
78 -re ".*$gdb_prompt $" { fail "print x.x" }
79 timeout { fail "(timeout) print x.x" }
83 # N is derived from A1 and A2, but not immediately -- two steps
84 # up in the hierarchy. Both A1 and A2 have a member 'x'.
85 send_gdb "print n.x\n"
87 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
90 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
93 -re ".*$gdb_prompt $" { fail "print n.x" }
94 timeout { fail "(timeout) print n.x" }
97 # J is derived from A1 twice. A1 has a member x.
98 send_gdb "print j.x\n"
100 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
103 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
106 -re ".*$gdb_prompt $" { fail "print j.x" }
107 timeout { fail "(timeout) print j.x" }
110 # JV is derived from A1 but A1 is a virtual base. Should not
111 # report an ambiguity in this case.
112 send_gdb "print jv.x\n"
114 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
115 fail "print jv.x (ambiguity reported)"
117 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
118 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
119 timeout { fail "(timeout) print jv.x" }
122 # JVA1 is derived from A1; A1 occurs as a virtual base in two
123 # ancestors, and as a non-virtual immediate base. Ambiguity must
125 send_gdb "print jva1.x\n"
127 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
130 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
133 -re ".*$gdb_prompt $" { fail "print jva1.x" }
134 timeout { fail "(timeout) print jva1.x" }
137 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
138 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
139 # be reported as A1 and A2 both have a member 'x'.
140 send_gdb "print jva2.x\n"
142 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
145 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
148 -re ".*$gdb_prompt $" { fail "print jva2.x" }
149 timeout { fail "(timeout) print jva2.x" }
152 # JVA1V is derived from A1; A1 occurs as a virtual base in two
153 # ancestors, and also as a virtual immediate base. Ambiguity must
155 send_gdb "print jva1v.x\n"
157 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
158 fail "print jva1v.x (ambiguity reported)"
160 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
161 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
162 timeout { fail "(timeout) print jva1v.x" }
165 # Now check for ambiguous bases.
167 # J is derived from A1 twice; report ambiguity if a J is
169 send_gdb "print (A1)j\n"
171 -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 $" {
174 -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 $" {
177 -re ".*$gdb_prompt $" { fail "print (A1)j" }
178 timeout { fail "(timeout) print (A1)j" }
181 # JV is derived from A1 twice, but A1 is a virtual base; should
182 # not report ambiguity when a JV is cast to an A1.
183 send_gdb "print (A1)jv\n"
185 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
186 fail "print (A1)jv (ambiguity reported)"
188 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
189 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
190 timeout { fail "(timeout) print (A1)jv" }
193 # JVA1 is derived from A1; A1 is a virtual base and also a
194 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
195 send_gdb "print (A1)jva1\n"
197 -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 $" {
198 pass "print (A1)jva1"
200 -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 $" {
201 pass "print (A1)jva1"
203 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
204 timeout { fail "(timeout) print (A1)jva1" }
207 # JVA1V is derived from A1; A1 is a virtual base indirectly
208 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
209 send_gdb "print (A1)jva1v\n"
211 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
212 fail "print (A1)jva1v (ambiguity reported)"
214 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
216 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
217 timeout { fail "(timeout) print (A1)jva1v" }