diff options
author | Pedro Alves <pedro@palves.net> | 2020-08-28 21:10:59 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2020-10-12 18:06:09 +0100 |
commit | 87a37e5e078f506fa9905b74e9238593c537fcd5 (patch) | |
tree | 0932e1430659ea8fe441479d43dbe14e02708ca3 /gdb/testsuite | |
parent | 71e1b6b0ac9403d7fda91890f0d2881b6d1697d6 (diff) | |
download | gdb-87a37e5e078f506fa9905b74e9238593c537fcd5.zip gdb-87a37e5e078f506fa9905b74e9238593c537fcd5.tar.gz gdb-87a37e5e078f506fa9905b74e9238593c537fcd5.tar.bz2 |
Reject ambiguous C++ field accesses (PR exp/26602)
The gdb.cp/ambiguous.exp testcase had been disabled for many years,
but recently it was re-enabled. However, it is failing everywhere.
That is because it is testing an old feature that is gone from GDB.
The testcase is expecting to see an ambiguous field warning, like:
# X is derived from A1 and A2; both A1 and A2 have a member 'x'
send_gdb "print x.x\n"
gdb_expect {
-re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
pass "print x.x"
}
-re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" {
pass "print x.x"
}
-re ".*$gdb_prompt $" { fail "print x.x" }
timeout { fail "(timeout) print x.x" }
}
However, GDB just accesses one of the candidates without warning or
error:
print x.x
$1 = 1431655296
(gdb) FAIL: gdb.cp/ambiguous.exp: print x.x
(The weird number is because the testcase does not initialize the
variables.)
The testcase come in originally with the big HP merge:
+Sun Jan 10 23:44:11 1999 David Taylor <taylor@texas.cygnus.com>
+
+
+ The following files are part of the HP merge; some had longer
+ names at HP, but have been renamed to be no more than 14
+ characters in length.
Looking at the tree back then, we find that warning:
/* Helper function used by value_struct_elt to recurse through baseclasses.
Look for a field NAME in ARG1. Adjust the address of ARG1 by OFFSET bytes,
and search in it assuming it has (class) type TYPE.
If found, return value, else return NULL.
If LOOKING_FOR_BASECLASS, then instead of looking for struct fields,
look for a baseclass named NAME. */
static value_ptr
search_struct_field (name, arg1, offset, type, looking_for_baseclass)
char *name;
register value_ptr arg1;
int offset;
register struct type *type;
int looking_for_baseclass;
{
int found = 0;
char found_class[1024];
value_ptr v;
struct type *vbase = NULL;
found_class[0] = '\000';
v = search_struct_field_aux (name, arg1, offset, type, looking_for_baseclass, &found, found_class, &vbase);
if (found > 1)
warning ("%s ambiguous; using %s::%s. Use a cast to disambiguate.",
name, found_class, name);
return v;
}
However, in current GDB, search_struct_field does not handle the
ambiguous field case, nor is that warning found anywhere. Somehow it
got lost over the years. That seems like a regression, because the
compiler (as per language rules) rejects the ambiguous accesses as
well. E.g.:
gdb.cp/ambiguous.cc:98:5: error: request for member 'x' is ambiguous
98 | x.x = 1;
| ^
gdb.cp/ambiguous.cc:10:7: note: candidates are: 'int A2::x'
10 | int x;
| ^
gdb.cp/ambiguous.cc:4:7: note: 'int A1::x'
4 | int x;
| ^
This patch restores the feature, though implemented differently and
with better user experience, IMHO. An ambiguous access is now an
error instead of a warning, and also GDB shows you all the candidates,
like:
(gdb) print x.x
Request for member 'x' is ambiguous in type 'X'. Candidates are:
'int A1::x' (X -> A1)
'int A2::x' (X -> A2)
(gdb) print j.x
Request for member 'x' is ambiguous in type 'J'. Candidates are:
'int A1::x' (J -> K -> A1)
'int A1::x' (J -> L -> A1)
Users can then fix their commands by casting or by specifying the
baseclass explicitly, like:
(gdb) p x.A1::x
$1 = 1
(gdb) p x.A2::x
$2 = 2
(gdb) p ((A1) x).x
$3 = 1
(gdb) p ((A2) x).x
$4 = 2
(gdb) p j.K::x
$12 = 1
(gdb) p j.L::x
$13 = 2
(gdb) p j.A1::x
base class 'A1' is ambiguous in type 'J'
The last error I've not touched; could be improved to also list the
baseclass candidates.
The showing the class "path" for each candidate was inspired by GCC's
output when you try an ambiguous cast:
gdb.cp/ambiguous.cc:161:8: error: ambiguous conversion from derived class 'const JVA1' to base class 'const A1':
class JVA1 -> class KV -> class A1
class JVA1 -> class A1
(A1) jva1;
^~~~
I did not include the "class" word as it seemed unnecessarily
repetitive, but I can include it if people prefer it:
(gdb) print j.x
Request for member 'x' is ambiguous in type 'J'. Candidates are:
'int A1::x' (class J -> class K -> class A1)
'int A1::x' (class J -> class L -> class A1)
The testcase is adjusted accordingly. I also took the chance to
modernize it at the same time.
Also, as mentioned above, the testcase doesn't currently initialize
the tested variables. This patch inializes them all, giving each
field a distinct value, so that we can be sure that GDB is accessing
the right fields / offsets. The testcase is extended accordingly.
Unfortunately, this exposes a bug, not addressed in this patch. The
bug is around a class that inherits from A1 directly and also inherits
from two other distinct base classes that inherit virtually from A1 in
turn:
print jva1.KV::x
$51 = 1431665544
(gdb) FAIL: gdb.cp/ambiguous.exp: all fields: print jva1.KV::x
print jva1.KV::y
$52 = 21845
(gdb) FAIL: gdb.cp/ambiguous.exp: all fields: print jva1.KV::y
(gdb) print /x (KV)jva1
$4 = {<A1> = <invalid address>, _vptr.KV = 0x555555557b88 <vtable for JVA1+24>, i = 0x457}
(gdb) print /x (A1)(KV)jva1
Cannot access memory at address 0x0
Since that's an orthogonal issue, I filed PR c++/26550 and kfailed the
tests that fail because of it.
gdb/ChangeLog:
PR exp/26602
* valops.c (struct struct_field_searcher): New.
(update_search_result): Rename to ...
(struct_field_searcher::update_result): ... this. Simplify
prototype. Record all found fields.
(do_search_struct_field): Rename to ...
(struct_field_searcher::search): ... this. Simplify prototype.
Maintain stack of visited baseclass path. Call update_result for
fields too. Keep searching fields in baseclasses instead of
stopping at the first found field.
(search_struct_field): Use struct_field_searcher. When looking
for fields, report ambiguous access attempts.
gdb/testsuite/ChangeLog:
PR exp/26602
PR c++/26550
* gdb.cp/ambiguous.cc (marker1): Delete.
(main): Initialize all the fields of the locals. Replace marker1
call with a "set breakpoint here" marker.
* gdb.cp/ambiguous.exp: Modernize. Use gdb_continue_to_breakpoint
instead of running to marker1. Add tests printing all the
variables and all the fields of the variables.
(test_ambiguous): New proc, expecting the new GDB output when a
field access is ambiguous. Change all "warning: X ambiguous"
tests to use it.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 14 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/ambiguous.cc | 85 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/ambiguous.exp | 329 |
3 files changed, 272 insertions, 156 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index aefdcba..d508701 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2020-10-12 Pedro Alves <pedro@palves.net> + + PR exp/26602 + PR c++/26550 + * gdb.cp/ambiguous.cc (marker1): Delete. + (main): Initialize all the fields of the locals. Replace marker1 + call with a "set breakpoint here" marker. + * gdb.cp/ambiguous.exp: Modernize. Use gdb_continue_to_breakpoint + instead of running to marker1. Add tests printing all the + variables and all the fields of the variables. + (test_ambiguous): New proc, expecting the new GDB output when a + field access is ambiguous. Change all "warning: X ambiguous" + tests to use it. + 2020-10-12 Gary Benson <gbenson@redhat.com> * gdb.base/msym-bp.c (foo): Add __attribute__ ((used)). diff --git a/gdb/testsuite/gdb.cp/ambiguous.cc b/gdb/testsuite/gdb.cp/ambiguous.cc index 93fba1c..a556865 100644 --- a/gdb/testsuite/gdb.cp/ambiguous.cc +++ b/gdb/testsuite/gdb.cp/ambiguous.cc @@ -1,9 +1,4 @@ -void marker1() -{ - return; -} - class A1 { public: int x; @@ -102,7 +97,81 @@ int main() i += k.i + m.w + a1.x + a2.x + a3.x + x.z + l.z + n.r + j.j; - marker1(); - - return 0; + /* Initialize all the fields. Keep the order the same as in the + .exp file. */ + + a1.x = 1; + a1.y = 2; + + a2.x = 1; + a2.y = 2; + + a3.x = 1; + a3.y = 2; + + x.A1::x = 1; + x.A1::y = 2; + x.A2::x = 3; + x.A2::y = 4; + x.z = 5; + + l.x = 1; + l.y = 2; + l.z = 3; + + m.x = 1; + m.y = 2; + m.w = 3; + + n.A1::x = 1; + n.A1::y = 2; + n.A2::x = 3; + n.A2::y = 4; + n.w = 5; + n.r = 6; + n.z = 7; + + k.x = 1; + k.y = 2; + k.i = 3; + + j.K::x = 1; + j.K::y = 2; + j.L::x = 3; + j.L::y = 4; + j.i = 5; + j.z = 6; + j.j = 7; + + jv.x = 1; + jv.y = 2; + jv.i = 3; + jv.z = 4; + jv.jv = 5; + + jva1.KV::x = 1; + jva1.KV::y = 2; + jva1.LV::x = 3; + jva1.LV::y = 4; + jva1.z = 5; + jva1.i = 6; + jva1.jva1 = 7; + + jva2.KV::x = 1; + jva2.KV::y = 2; + jva2.LV::x = 3; + jva2.LV::y = 4; + jva2.A2::x = 5; + jva2.A2::y = 6; + jva2.z = 7; + jva2.i = 8; + jva2.jva2 = 9; + + jva1v.x = 1; + jva1v.y = 2; + jva1v.z = 3; + jva1v.i = 4; + jva1v.jva1v = 5; + + return 0; /* set breakpoint here */ } diff --git a/gdb/testsuite/gdb.cp/ambiguous.exp b/gdb/testsuite/gdb.cp/ambiguous.exp index 4d01c10..b7fec1b 100644 --- a/gdb/testsuite/gdb.cp/ambiguous.exp +++ b/gdb/testsuite/gdb.cp/ambiguous.exp @@ -15,15 +15,9 @@ # This file is part of the gdb testsuite -# tests relating to ambiguous class members -# Written by Satish Pai <pai@apollo.hp.com> 1997-07-28 - -# This file is part of the gdb testsuite - -# -# test running programs -# - +# Print out various class objects' members and check that the error +# about the field or baseclass being ambiguous is emitted at the right +# times. if { [skip_cplus_tests] } { continue } @@ -47,187 +41,226 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ return -1 } -# -# set it up at a breakpoint so we can play with the variable values -# if ![runto_main] then { perror "couldn't run to breakpoint" continue } -send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $" - send_gdb "cont\n" - gdb_expect { - -re "Break.* marker1 \\(\\) at .*:$decimal.*$gdb_prompt $" { - send_gdb "up\n" - gdb_expect { - -re ".*$gdb_prompt $" { pass "up from marker1" } - timeout { fail "up from marker1" } - } - } - -re "$gdb_prompt $" { fail "continue to marker1" } - timeout { fail "(timeout) continue to marker1" } +# Run to a breakpoint after the variables have been initialized so we +# can play with the variable values. + +set lineno [gdb_get_line_number "set breakpoint here"] + +gdb_breakpoint $lineno +gdb_continue_to_breakpoint "breakpoint here" + +set number -?$decimal + +with_test_prefix "all vars" { + gdb_test "print a1" \ + " = \{x = 1, y = 2\}" + + gdb_test "print a2" \ + " = \{x = 1, y = 2\}" + + gdb_test "print a3" \ + " = \{x = 1, y = 2\}" + + gdb_test "print x" \ + " = \{<A1> = \{x = 1, y = 2\}, <A2> = \{x = 3, y = 4\}, z = 5\}" + + gdb_test "print l" \ + " = \{<A1> = \{x = 1, y = 2\}, z = 3\}" + + gdb_test "print m" \ + " = \{<A2> = \{x = 1, y = 2\}, w = 3\}" + + gdb_test "print n" \ + " = \{<L> = \{<A1> = \{x = 1, y = 2\}, z = 7\}, <M> = \{<A2> = \{x = 3, y = 4\}, w = 5\}, r = 6\}" + + gdb_test "print k" \ + " = \{<A1> = \{x = 1, y = 2\}, i = 3\}" + + gdb_test "print j" \ + " = {<K> = {<A1> = {x = 1, y = 2}, i = 5}, <L> = {<A1> = {x = 3, y = 4}, z = 6}, j = 7}" + + gdb_test "print jv" \ + " = \{<KV> = \{<A1> = \{x = 1, y = 2\}, _vptr.KV = $hex <vtable for JV.*>, i = 3\}, <LV> = \{_vptr.LV = $hex <VTT for JV>, z = 4\}, jv = 5\}" + + # No way to initialize one of the A1's, so just take any number there. + gdb_test "print jva1" \ + " = \{<KV> = \{<A1> = \{x = 3, y = 4\}, _vptr.KV = $hex <vtable for JVA1.*>, i = 6\}, <LV> = \{_vptr.LV = $hex <VTT for JVA1>, z = 5\}, <A1> = \{x = $number, y = $number\}, jva1 = 7\}" + + gdb_test "print jva2" \ + " = \{<KV> = \{<A1> = \{x = 3, y = 4\}, _vptr.KV = $hex <vtable for JVA2.*>, i = 8\}, <LV> = \{_vptr.LV = $hex <VTT for JVA2>, z = 7\}, <A2> = \{x = 5, y = 6\}, jva2 = 9\}" + + gdb_test "print jva1v" \ + " = \{<KV> = \{<A1> = \{x = 1, y = 2\}, _vptr.KV = $hex <vtable for JVA1V+.*>, i = 4\}, <LV> = \{_vptr.LV = $hex <VTT for JVA1V>, z = 3\}, jva1v = 5\}" +} + +# Check that we can access all the fields correctly, using the same +# syntax as used in the .cc file. Keep the order here in sync with +# the .cc file. +with_test_prefix "all fields" { + gdb_test "print a1.x" " = 1" + gdb_test "print a1.y" " = 2" + + gdb_test "print a2.x" " = 1" + gdb_test "print a2.y" " = 2" + + gdb_test "print a3.x" " = 1" + gdb_test "print a3.y" " = 2" + + gdb_test "print x.A1::x" " = 1" + gdb_test "print x.A1::y" " = 2" + gdb_test "print x.A2::x" " = 3" + gdb_test "print x.A2::y" " = 4" + gdb_test "print x.z" " = 5" + + gdb_test "print l.x" " = 1" + gdb_test "print l.y" " = 2" + gdb_test "print l.z" " = 3" + + gdb_test "print m.x" " = 1" + gdb_test "print m.y" " = 2" + gdb_test "print m.w" " = 3" + + gdb_test "print n.A1::x" " = 1" + gdb_test "print n.A1::y" " = 2" + gdb_test "print n.A2::x" " = 3" + gdb_test "print n.A2::y" " = 4" + gdb_test "print n.w" " = 5" + gdb_test "print n.r" " = 6" + gdb_test "print n.z" " = 7" + + gdb_test "print k.x" " = 1" + gdb_test "print k.y" " = 2" + gdb_test "print k.i" " = 3" + + gdb_test "print j.K::x" " = 1" + gdb_test "print j.K::y" " = 2" + gdb_test "print j.L::x" " = 3" + gdb_test "print j.L::y" " = 4" + gdb_test "print j.i" " = 5" + gdb_test "print j.z" " = 6" + gdb_test "print j.j" " = 7" + + gdb_test "print jv.x" " = 1" + gdb_test "print jv.y" " = 2" + gdb_test "print jv.i" " = 3" + gdb_test "print jv.z" " = 4" + gdb_test "print jv.jv" " = 5" + + setup_kfail "c++/26550" *-*-* + gdb_test "print jva1.KV::x" " = 1" + setup_kfail "c++/26550" *-*-* + gdb_test "print jva1.KV::y" " = 2" + setup_kfail "c++/26550" *-*-* + gdb_test "print jva1.LV::x" " = 3" + setup_kfail "c++/26550" *-*-* + gdb_test "print jva1.LV::y" " = 4" + gdb_test "print jva1.z" " = 5" + gdb_test "print jva1.i" " = 6" + gdb_test "print jva1.jva1" "= 7" + + setup_kfail "c++/26550" *-*-* + gdb_test "print jva2.KV::x" " = 1" + setup_kfail "c++/26550" *-*-* + gdb_test "print jva2.KV::y" " = 2" + setup_kfail "c++/26550" *-*-* + gdb_test "print jva2.LV::x" " = 3" + setup_kfail "c++/26550" *-*-* + gdb_test "print jva2.LV::y" " = 4" + gdb_test "print jva2.A2::x" " = 5" + gdb_test "print jva2.A2::y" " = 6" + gdb_test "print jva2.z" " = 7" + gdb_test "print jva2.i" " = 8" + gdb_test "print jva2.jva2" "= 9" + + gdb_test "print jva1v.x" " = 1" + gdb_test "print jva1v.y" " = 2" + gdb_test "print jva1v.z" " = 3" + gdb_test "print jva1v.i" " = 4" + gdb_test "print jva1v.jva1v" " = 5" +} + +# Test that printing WHAT reports an error about FIELD being ambiguous +# in TYPE, and that the candidates are CANDIDATES. +proc test_ambiguous {what field type candidates} { + set msg "Request for member '$field' is ambiguous in type '$type'. Candidates are:" + + foreach c $candidates { + set c_re [string_to_regexp $c] + append msg "\r\n $c_re" } -# print out various class objects' members. The values aren't -# important, just check that the warning is emitted at the -# right times. + gdb_test "print $what" $msg +} # X is derived from A1 and A2; both A1 and A2 have a member 'x' -setup_kfail gdb/26602 *-*-* -send_gdb "print x.x\n" -gdb_expect { - -re "warning: x ambiguous; using X::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print x.x" - } - -re "warning: x ambiguous; using X::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print x.x" - } - -re ".*$gdb_prompt $" { fail "print x.x" } - timeout { fail "(timeout) print x.x" } +test_ambiguous "x.x" "x" "X" { + "'int A1::x' (X -> A1)" + "'int A2::x' (X -> A2)" } - # N is derived from A1 and A2, but not immediately -- two steps # up in the hierarchy. Both A1 and A2 have a member 'x'. -setup_kfail gdb/26602 *-*-* -send_gdb "print n.x\n" -gdb_expect { - -re "warning: x ambiguous; using N::M::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print n.x" - } - -re "warning: x ambiguous; using N::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print n.x" - } - -re ".*$gdb_prompt $" { fail "print n.x" } - timeout { fail "(timeout) print n.x" } +test_ambiguous "n.x" "x" "N" { + "'int A1::x' (N -> L -> A1)" + "'int A2::x' (N -> M -> A2)" } -# J is derived from A1 twice. A1 has a member x. -setup_kfail gdb/26602 *-*-* -send_gdb "print j.x\n" -gdb_expect { - -re "warning: x ambiguous; using J::L::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print j.x" - } - -re "warning: x ambiguous; using J::K::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print j.x" - } - -re ".*$gdb_prompt $" { fail "print j.x" } - timeout { fail "(timeout) print j.x" } +# J is derived from A1 twice. A1 has a member x. +test_ambiguous "j.x" "x" "J" { + "'int A1::x' (J -> K -> A1)" + "'int A1::x' (J -> L -> A1)" } # JV is derived from A1 but A1 is a virtual base. Should not -# report an ambiguity in this case. -send_gdb "print jv.x\n" -gdb_expect { - -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - fail "print jv.x (ambiguity reported)" - } - -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jv.x" } - -re ".*$gdb_prompt $" { fail "print jv.x (??)" } - timeout { fail "(timeout) print jv.x" } -} +# report an ambiguity in this case. +gdb_test "print jv.x" " = 1" # JVA1 is derived from A1; A1 occurs as a virtual base in two # ancestors, and as a non-virtual immediate base. Ambiguity must -# be reported. -setup_kfail gdb/26602 *-*-* -send_gdb "print jva1.x\n" -gdb_expect { - -re "warning: x ambiguous; using JVA1::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print jva1.x" - } - -re "warning: x ambiguous; using JVA1::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print jva1.x" - } - -re ".*$gdb_prompt $" { fail "print jva1.x" } - timeout { fail "(timeout) print jva1.x" } +# be reported. +test_ambiguous "jva1.x" "x" "JVA1" { + "'int A1::x' (JVA1 -> KV -> A1)" + "'int A1::x' (JVA1 -> A1)" } # JVA2 is derived from A1 & A2; A1 occurs as a virtual base in two # ancestors, and A2 is a non-virtual immediate base. Ambiguity must # be reported as A1 and A2 both have a member 'x'. -setup_kfail gdb/26602 *-*-* -send_gdb "print jva2.x\n" -gdb_expect { - -re "warning: x ambiguous; using JVA2::A2::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print jva2.x" - } - -re "warning: x ambiguous; using JVA2::KV::A1::x. Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - pass "print jva2.x" - } - -re ".*$gdb_prompt $" { fail "print jva2.x" } - timeout { fail "(timeout) print jva2.x" } +test_ambiguous "jva2.x" "x" "JVA2" { + "'int A1::x' (JVA2 -> KV -> A1)" + "'int A2::x' (JVA2 -> A2)" } # JVA1V is derived from A1; A1 occurs as a virtual base in two # ancestors, and also as a virtual immediate base. Ambiguity must # not be reported. -send_gdb "print jva1v.x\n" -gdb_expect { - -re "warning: x ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { - fail "print jva1v.x (ambiguity reported)" - } - -re "\\$\[0-9\]* = \[-\]*\[0-9\]*\r\n$gdb_prompt $" { pass "print jva1v.x" } - -re ".*$gdb_prompt $" { fail "print jva1v.x (??)" } - timeout { fail "(timeout) print jva1v.x" } -} +gdb_test "print jva1v.x" " = 1" # Now check for ambiguous bases. # J is derived from A1 twice; report ambiguity if a J is # cast to an A1. -setup_kfail gdb/26602 *-*-* -send_gdb "print (A1)j\n" -gdb_expect { - -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 $" { - pass "print (A1)j" - } - -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 $" { - pass "print (A1)j" - } - -re ".*$gdb_prompt $" { fail "print (A1)j" } - timeout { fail "(timeout) print (A1)j" } -} +gdb_test "print (A1)j" "base class 'A1' is ambiguous in type 'J'" # JV is derived from A1 twice, but A1 is a virtual base; should # not report ambiguity when a JV is cast to an A1. -send_gdb "print (A1)jv\n" -gdb_expect { - -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { - fail "print (A1)jv (ambiguity reported)" - } - -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jv" } - -re ".*$gdb_prompt $" { fail "print (A1)jv (??)" } - timeout { fail "(timeout) print (A1)jv" } -} +gdb_test "print (A1)jv" " = {x = 1, y = 2}" # JVA1 is derived from A1; A1 is a virtual base and also a # non-virtual base. Must report ambiguity if a JVA1 is cast to an A1. -setup_kfail gdb/26602 *-*-* -send_gdb "print (A1)jva1\n" -gdb_expect { - -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 $" { - pass "print (A1)jva1" - } - -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 $" { - pass "print (A1)jva1" - } - -re ".*$gdb_prompt $" { fail "print (A1)jva1" } - timeout { fail "(timeout) print (A1)jva1" } -} +gdb_test "print (A1)jva1" "base class 'A1' is ambiguous in type 'JVA1'" + +# Add an intermediate cast to KV, and it should work. +setup_kfail "c++/26550" *-*-* +gdb_test "print (KV)jva1" " = \{<A1> = \{x = 3, y = 4\}, _vptr.KV = $hex <VTT for KV>, i = 6\}" +setup_kfail "c++/26550" *-*-* +gdb_test "print (A1)(KV)jva1" " = \{x = 3, y = 4\}" # JVA1V is derived from A1; A1 is a virtual base indirectly # and also directly; must not report ambiguity when a JVA1V is cast to an A1. -send_gdb "print (A1)jva1v\n" -gdb_expect { - -re "warning: A1 ambiguous.*Use a cast to disambiguate.\r\n\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { - fail "print (A1)jva1v (ambiguity reported)" - } - -re "\\$\[0-9\]* = \{x = \[-\]*\[0-9\]*, y = \[-\]*\[0-9\]*\}\r\n$gdb_prompt $" { pass "print (A1)jva1v" - } - -re ".*$gdb_prompt $" { fail "print (A1)jva1v (??)" } - timeout { fail "(timeout) print (A1)jva1v" } -} - +gdb_test "print (A1)jva1v" " = {x = 1, y = 2}" |