1 # Copyright 1998-2020 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 3 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, see <http://www.gnu.org/licenses/>.
16 # This file is part of the gdb testsuite
18 # tests relating to ambiguous class members
19 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-28
21 # This file is part of the gdb testsuite
24 # test running programs
28 if { [skip_cplus_tests] } { continue }
32 if [get_compiler_info "c++"] {
36 if { [test_compiler_info gcc-*] } then { continue }
38 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
43 # set it up at a breakpoint so we can play with the variable values
45 if ![runto_main] then {
46 perror "couldn't run to breakpoint"
50 send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $"
53 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" {
56 -re ".*$gdb_prompt $" { pass "up from marker1" }
57 timeout { fail "up from marker1" }
60 -re "$gdb_prompt $" { fail "continue to marker1" }
61 timeout { fail "(timeout) continue to marker1" }
64 # print out various class objects' members. The values aren't
65 # important, just check that the warning is emitted at the
68 # X is derived from A1 and A2; both A1 and A2 have a member 'x'
69 send_gdb "print x.x\n"
71 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
74 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
77 -re ".*$gdb_prompt $" { fail "print x.x" }
78 timeout { fail "(timeout) print x.x" }
82 # N is derived from A1 and A2, but not immediately -- two steps
83 # up in the hierarchy. Both A1 and A2 have a member 'x'.
84 send_gdb "print n.x\n"
86 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
89 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
92 -re ".*$gdb_prompt $" { fail "print n.x" }
93 timeout { fail "(timeout) print n.x" }
96 # J is derived from A1 twice. A1 has a member x.
97 send_gdb "print j.x\n"
99 -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
102 -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
105 -re ".*$gdb_prompt $" { fail "print j.x" }
106 timeout { fail "(timeout) print j.x" }
109 # JV is derived from A1 but A1 is a virtual base. Should not
110 # report an ambiguity in this case.
111 send_gdb "print jv.x\n"
113 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
114 fail "print jv.x (ambiguity reported)"
116 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" }
117 -re ".*$gdb_prompt $" { fail "print jv.x (??)" }
118 timeout { fail "(timeout) print jv.x" }
121 # JVA1 is derived from A1; A1 occurs as a virtual base in two
122 # ancestors, and as a non-virtual immediate base. Ambiguity must
124 send_gdb "print jva1.x\n"
126 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
129 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
132 -re ".*$gdb_prompt $" { fail "print jva1.x" }
133 timeout { fail "(timeout) print jva1.x" }
136 # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two
137 # ancestors, and A2 is a non-virtual immediate base. Ambiguity must
138 # be reported as A1 and A2 both have a member 'x'.
139 send_gdb "print jva2.x\n"
141 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
144 -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
147 -re ".*$gdb_prompt $" { fail "print jva2.x" }
148 timeout { fail "(timeout) print jva2.x" }
151 # JVA1V is derived from A1; A1 occurs as a virtual base in two
152 # ancestors, and also as a virtual immediate base. Ambiguity must
154 send_gdb "print jva1v.x\n"
156 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
157 fail "print jva1v.x (ambiguity reported)"
159 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" }
160 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" }
161 timeout { fail "(timeout) print jva1v.x" }
164 # Now check for ambiguous bases.
166 # J is derived from A1 twice; report ambiguity if a J is
168 send_gdb "print (A1)j\n"
170 -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 $" {
173 -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 $" {
176 -re ".*$gdb_prompt $" { fail "print (A1)j" }
177 timeout { fail "(timeout) print (A1)j" }
180 # JV is derived from A1 twice, but A1 is a virtual base; should
181 # not report ambiguity when a JV is cast to an A1.
182 send_gdb "print (A1)jv\n"
184 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
185 fail "print (A1)jv (ambiguity reported)"
187 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" }
188 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" }
189 timeout { fail "(timeout) print (A1)jv" }
192 # JVA1 is derived from A1; A1 is a virtual base and also a
193 # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1.
194 send_gdb "print (A1)jva1\n"
196 -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 $" {
197 pass "print (A1)jva1"
199 -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 $" {
200 pass "print (A1)jva1"
202 -re ".*$gdb_prompt $" { fail "print (A1)jva1" }
203 timeout { fail "(timeout) print (A1)jva1" }
206 # JVA1V is derived from A1; A1 is a virtual base indirectly
207 # and also directly; must not report ambiguity when a JVA1V is cast to an A1.
208 send_gdb "print (A1)jva1v\n"
210 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" {
211 fail "print (A1)jva1v (ambiguity reported)"
213 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v"
215 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" }
216 timeout { fail "(timeout) print (A1)jva1v" }