Fix crash with C++ qualified names
authorTom Tromey <tom@tromey.com>
Fri, 23 Dec 2022 19:55:10 +0000 (12:55 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 9 Jan 2023 19:16:02 +0000 (12:16 -0700)
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 <blarsen@redhat.com>
gdb/eval.c
gdb/testsuite/gdb.cp/ambiguous.exp

index 05e35941101a7ff15097b5f52f122aaa9316bf0e..bb42e693b179d2491ab5d17172d993178a6e2923 100644 (file)
@@ -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);
 
index b430b039887c2d7c743659498fd12a39b11396d9..966d99ae595927febd7ca10164f6d72a069174b3 100644 (file)
@@ -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"