[PING^2] [PATCH] Fix dynamic_cast operator
Siva Chandra
sivachandra@google.com
Mon Apr 28 14:13:00 GMT 2014
Original post: https://sourceware.org/ml/gdb-patches/2014-04/msg00089.html
ChangeLog:
2014-04-28 Siva Chandra Reddy <sivachandra@google.com>
* valops.c (value_dynamic_cast): Fix mixup between rtti_type
and resolved_type.
testsuite/
* gdb.cp/casts.exp: Adjust expected result for few tests.
-------------- next part --------------
diff --git a/gdb/testsuite/gdb.cp/casts.exp b/gdb/testsuite/gdb.cp/casts.exp
index 9122450..dd848db 100644
--- a/gdb/testsuite/gdb.cp/casts.exp
+++ b/gdb/testsuite/gdb.cp/casts.exp
@@ -151,8 +151,7 @@ gdb_test "print dynamic_cast<Alpha &> (derived)" \
"dynamic_cast simple upcast to reference"
gdb_test "print dynamic_cast<Derived *> (ad)" \
- " = \\(Derived \\*\\) ${nonzero_hex}( <vtable for Derived.*>)?" \
- "dynamic_cast simple downcast"
+ " = \\(Derived \\*\\) ${nonzero_hex}" "dynamic_cast simple downcast"
gdb_test "print dynamic_cast<VirtuallyDerived *> (add)" \
" = \\(VirtuallyDerived \\*\\) $nonzero_hex" \
@@ -167,8 +166,7 @@ gdb_test "print dynamic_cast<VirtuallyDerived &> (*ad)" \
"dynamic_cast to reference to non-existing base"
gdb_test "print dynamic_cast<DoublyDerived *> (add)" \
- " = \\(DoublyDerived \\*\\) ${nonzero_hex}( <vtable for DoublyDerived.*>)?" \
- "dynamic_cast unique downcast"
+ " = \\(DoublyDerived \\*\\) ${nonzero_hex}" "dynamic_cast unique downcast"
gdb_test "print dynamic_cast<Gamma *> (add)" \
" = \\(Gamma \\*\\) $nonzero_hex" \
diff --git a/gdb/valops.c b/gdb/valops.c
index 7f2d5f0..b68c4e1 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -801,14 +801,14 @@ value_dynamic_cast (struct type *type, struct value *arg)
&& TYPE_CODE (TYPE_TARGET_TYPE (resolved_type)) == TYPE_CODE_VOID)
return value_at_lazy (type, addr);
- tem = value_at (type, addr);
- type = value_type (tem);
+ tem = value_at (rtti_type, addr);
/* The first dynamic check specified in 5.2.7. */
if (is_public_ancestor (arg_type, TYPE_TARGET_TYPE (resolved_type)))
{
if (class_types_same_p (rtti_type, TYPE_TARGET_TYPE (resolved_type)))
- return tem;
+ return value_from_pointer (type, addr);
+
result = NULL;
if (dynamic_cast_check_1 (TYPE_TARGET_TYPE (resolved_type),
value_contents_for_printing (tem),
More information about the Gdb-patches
mailing list