ambiguous.exp revision 1.9
1# Copyright 1998-2020 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 unsupported "couldn't find a valid c++ compiler" 34 return -1 35} 36 37set additional_flags "" 38if {[test_compiler_info {gcc-[0-9]-*}]} { 39 # GCCs prior to 10.1 do not support -Wno-inaccessible-base. 40 set additional_flags "additional_flags=-w" 41} elseif {[test_compiler_info gcc*] || [test_compiler_info clang*]} { 42 set additional_flags "additional_flags=-Wno-inaccessible-base" 43} 44 45if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ 46 [list debug c++ $additional_flags]]} { 47 return -1 48} 49 50# 51# set it up at a breakpoint so we can play with the variable values 52# 53if ![runto_main] then { 54 perror "couldn't run to breakpoint" 55 continue 56} 57 58send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $" 59 send_gdb "cont\n" 60 gdb_expect { 61 -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" { 62 send_gdb "up\n" 63 gdb_expect { 64 -re ".*$gdb_prompt $" { pass "up from marker1" } 65 timeout { fail "up from marker1" } 66 } 67 } 68 -re "$gdb_prompt $" { fail "continue to marker1" } 69 timeout { fail "(timeout) continue to marker1" } 70 } 71 72# print out various class objects' members. The values aren't 73# important, just check that the warning is emitted at the 74# right times. 75 76# X is derived from A1 and A2; both A1 and A2 have a member 'x' 77setup_kfail gdb/26602 *-*-* 78send_gdb "print x.x\n" 79gdb_expect { 80 -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 81 pass "print x.x" 82 } 83 -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 84 pass "print x.x" 85 } 86 -re ".*$gdb_prompt $" { fail "print x.x" } 87 timeout { fail "(timeout) print x.x" } 88} 89 90 91# N is derived from A1 and A2, but not immediately -- two steps 92# up in the hierarchy. Both A1 and A2 have a member 'x'. 93setup_kfail gdb/26602 *-*-* 94send_gdb "print n.x\n" 95gdb_expect { 96 -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 97 pass "print n.x" 98 } 99 -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 100 pass "print n.x" 101 } 102 -re ".*$gdb_prompt $" { fail "print n.x" } 103 timeout { fail "(timeout) print n.x" } 104} 105 106# J is derived from A1 twice. A1 has a member x. 107setup_kfail gdb/26602 *-*-* 108send_gdb "print j.x\n" 109gdb_expect { 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 $" { 111 pass "print j.x" 112 } 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 $" { 114 pass "print j.x" 115 } 116 -re ".*$gdb_prompt $" { fail "print j.x" } 117 timeout { fail "(timeout) print j.x" } 118} 119 120# JV is derived from A1 but A1 is a virtual base. Should not 121# report an ambiguity in this case. 122send_gdb "print jv.x\n" 123gdb_expect { 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)" 126 } 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" } 130} 131 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 134# be reported. 135setup_kfail gdb/26602 *-*-* 136send_gdb "print jva1.x\n" 137gdb_expect { 138 -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 139 pass "print jva1.x" 140 } 141 -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 142 pass "print jva1.x" 143 } 144 -re ".*$gdb_prompt $" { fail "print jva1.x" } 145 timeout { fail "(timeout) print jva1.x" } 146} 147 148# JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two 149# ancestors, and A2 is a non-virtual immediate base. Ambiguity must 150# be reported as A1 and A2 both have a member 'x'. 151setup_kfail gdb/26602 *-*-* 152send_gdb "print jva2.x\n" 153gdb_expect { 154 -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 155 pass "print jva2.x" 156 } 157 -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 pass "print jva2.x" 159 } 160 -re ".*$gdb_prompt $" { fail "print jva2.x" } 161 timeout { fail "(timeout) print jva2.x" } 162} 163 164# JVA1V is derived from A1; A1 occurs as a virtual base in two 165# ancestors, and also as a virtual immediate base. Ambiguity must 166# not be reported. 167send_gdb "print jva1v.x\n" 168gdb_expect { 169 -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { 170 fail "print jva1v.x (ambiguity reported)" 171 } 172 -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" } 173 -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" } 174 timeout { fail "(timeout) print jva1v.x" } 175} 176 177# Now check for ambiguous bases. 178 179# J is derived from A1 twice; report ambiguity if a J is 180# cast to an A1. 181setup_kfail gdb/26602 *-*-* 182send_gdb "print (A1)j\n" 183gdb_expect { 184 -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 $" { 185 pass "print (A1)j" 186 } 187 -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 $" { 188 pass "print (A1)j" 189 } 190 -re ".*$gdb_prompt $" { fail "print (A1)j" } 191 timeout { fail "(timeout) print (A1)j" } 192} 193 194# JV is derived from A1 twice, but A1 is a virtual base; should 195# not report ambiguity when a JV is cast to an A1. 196send_gdb "print (A1)jv\n" 197gdb_expect { 198 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { 199 fail "print (A1)jv (ambiguity reported)" 200 } 201 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" } 202 -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" } 203 timeout { fail "(timeout) print (A1)jv" } 204} 205 206# JVA1 is derived from A1; A1 is a virtual base and also a 207# non-virtual base. Must report ambiguity if a JVA1 is cast to an A1. 208setup_kfail gdb/26602 *-*-* 209send_gdb "print (A1)jva1\n" 210gdb_expect { 211 -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 $" { 212 pass "print (A1)jva1" 213 } 214 -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 $" { 215 pass "print (A1)jva1" 216 } 217 -re ".*$gdb_prompt $" { fail "print (A1)jva1" } 218 timeout { fail "(timeout) print (A1)jva1" } 219} 220 221# JVA1V is derived from A1; A1 is a virtual base indirectly 222# and also directly; must not report ambiguity when a JVA1V is cast to an A1. 223send_gdb "print (A1)jva1v\n" 224gdb_expect { 225 -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { 226 fail "print (A1)jva1v (ambiguity reported)" 227 } 228 -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v" 229 } 230 -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" } 231 timeout { fail "(timeout) print (A1)jva1v" } 232} 233 234