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