From: Tom Tromey Date: Fri, 23 Dec 2022 19:55:10 +0000 (-0700) Subject: Fix crash with C++ qualified names X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bf716a53bd8f725975979397b3c6b9d4bd4434ef;p=binutils-gdb.git Fix crash with C++ qualified names PR c++/29503 points out that something like "b->Base::member" will crash when 'b' does not have pointer type. This seems to be a simple oversight in eval_op_member. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29503 Reviewed-By: Bruno Larsen --- diff --git a/gdb/eval.c b/gdb/eval.c index 05e35941101..bb42e693b17 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1309,6 +1309,8 @@ eval_op_member (struct type *expect_type, struct expression *exp, case TYPE_CODE_MEMBERPTR: /* Now, convert these values to an address. */ + if (check_typedef (value_type (arg1))->code () != TYPE_CODE_PTR) + arg1 = value_addr (arg1); arg1 = value_cast_pointers (lookup_pointer_type (TYPE_SELF_TYPE (type)), arg1, 1); diff --git a/gdb/testsuite/gdb.cp/ambiguous.exp b/gdb/testsuite/gdb.cp/ambiguous.exp index b430b039887..966d99ae595 100644 --- a/gdb/testsuite/gdb.cp/ambiguous.exp +++ b/gdb/testsuite/gdb.cp/ambiguous.exp @@ -123,6 +123,7 @@ with_test_prefix "all fields" { 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->A2::y" " = 4" gdb_test "print n.w" " = 5" gdb_test "print n.r" " = 6" gdb_test "print n.z" " = 7"