ambiguous.exp revision 1.1
1# Copyright 1998-2014 Free Software Foundation, Inc. 2 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. 7# 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. 12# 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/>. 15 16# This file is part of the gdb testsuite 17 18# tests relating to ambiguous class members 19# Written by Satish Pai <pai@apollo.hp.com> 1997-07-28 20 21# This file is part of the gdb testsuite 22 23# 24# test running programs 25# 26 27 28if { [skip_cplus_tests] } { continue } 29 30standard_testfile .cc 31 32if [get_compiler_info "c++"] { 33 return -1 34} 35 36if { [test_compiler_info gcc-*] } then { continue } 37 38if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { 39 return -1 40} 41 42# 43# set it up at a breakpoint so we can play with the variable values 44# 45if ![runto_main] then { 46 perror "couldn't run to breakpoint" 47 continue 48} 49 50send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $" 51 send_gdb "cont\n" 52 gdb_expect { 53 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" { 54 send_gdb "up\n" 55 gdb_expect { 56 -re ".*$gdb_prompt $" { pass "up from marker1" } 57 timeout { fail "up from marker1" } 58 } 59 } 60 -re "$gdb_prompt $" { fail "continue to marker1" } 61 timeout { fail "(timeout) continue to marker1" } 62 } 63 64# print out various class objects' members. The values aren't 65# important, just check that the warning is emitted at the 66# right times. 67 68# X is derived from A1 and A2; both A1 and A2 have a member 'x' 69send_gdb "print x.x\n" 70gdb_expect { 71 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 72 pass "print x.x" 73 } 74 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 75 pass "print x.x" 76 } 77 -re ".*$gdb_prompt $" { fail "print x.x" } 78 timeout { fail "(timeout) print x.x" } 79} 80 81 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'. 84send_gdb "print n.x\n" 85gdb_expect { 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 $" { 87 pass "print n.x" 88 } 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 $" { 90 pass "print n.x" 91 } 92 -re ".*$gdb_prompt $" { fail "print n.x" } 93 timeout { fail "(timeout) print n.x" } 94} 95 96# J is derived from A1 twice. A1 has a member x. 97send_gdb "print j.x\n" 98gdb_expect { 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 $" { 100 pass "print j.x" 101 } 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 $" { 103 pass "print j.x" 104 } 105 -re ".*$gdb_prompt $" { fail "print j.x" } 106 timeout { fail "(timeout) print j.x" } 107} 108 109# JV is derived from A1 but A1 is a virtual base. Should not 110# report an ambiguity in this case. 111send_gdb "print jv.x\n" 112gdb_expect { 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)" 115 } 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" } 119} 120 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 123# be reported. 124send_gdb "print jva1.x\n" 125gdb_expect { 126 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 127 pass "print jva1.x" 128 } 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 $" { 130 pass "print jva1.x" 131 } 132 -re ".*$gdb_prompt $" { fail "print jva1.x" } 133 timeout { fail "(timeout) print jva1.x" } 134} 135 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'. 139send_gdb "print jva2.x\n" 140gdb_expect { 141 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 142 pass "print jva2.x" 143 } 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 $" { 145 pass "print jva2.x" 146 } 147 -re ".*$gdb_prompt $" { fail "print jva2.x" } 148 timeout { fail "(timeout) print jva2.x" } 149} 150 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 153# not be reported. 154send_gdb "print jva1v.x\n" 155gdb_expect { 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)" 158 } 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" } 162} 163 164# Now check for ambiguous bases. 165 166# J is derived from A1 twice; report ambiguity if a J is 167# cast to an A1. 168send_gdb "print (A1)j\n" 169gdb_expect { 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 $" { 171 pass "print (A1)j" 172 } 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 $" { 174 pass "print (A1)j" 175 } 176 -re ".*$gdb_prompt $" { fail "print (A1)j" } 177 timeout { fail "(timeout) print (A1)j" } 178} 179 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. 182send_gdb "print (A1)jv\n" 183gdb_expect { 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)" 186 } 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" } 190} 191 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. 194send_gdb "print (A1)jva1\n" 195gdb_expect { 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" 198 } 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" 201 } 202 -re ".*$gdb_prompt $" { fail "print (A1)jva1" } 203 timeout { fail "(timeout) print (A1)jva1" } 204} 205 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. 208send_gdb "print (A1)jva1v\n" 209gdb_expect { 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)" 212 } 213 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v" 214 } 215 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" } 216 timeout { fail "(timeout) print (A1)jva1v" } 217} 218 219