This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: fix cast to void
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> (gdb) p & (void) foobar
Pedro> $6 = (void *) 0xc215d9 <foobar>
Pedro> This should be an error.
Thanks for noticing this.
Here is a new patch.
Built and regtested on x86-64 Fedora 16.
Tom
2012-11-28 Pedro Alves <palves@redhat.com>
Tom Tromey <tromey@redhat.com>
* valops.c (value_cast): Move TYPE_CODE_VOID case earlier.
2012-11-28 Pedro Alves <palves@redhat.com>
Tom Tromey <tromey@redhat.com>
* gdb.base/exprs.exp: Add tests for cast to void.
diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp
index c6a07fa..f3de09e 100644
--- a/gdb/testsuite/gdb.base/exprs.exp
+++ b/gdb/testsuite/gdb.base/exprs.exp
@@ -270,3 +270,7 @@ gdb_test {print v_int_array_init[1]@1} { = \{20\}}
# gdb's {} extension
gdb_test_no_output "set variable v_short_array\[0\] = 42"
gdb_test "print {short} v_short_array" "$decimal = 42"
+
+# Regression tests for cast to void.
+gdb_test "print (void) v_int_pointer" " = void"
+gdb_test "print & (void) v_char" "value not located in memory."
diff --git a/gdb/valops.c b/gdb/valops.c
index 924b56d..9ec7e91 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -569,6 +569,10 @@ value_cast (struct type *type, struct value *arg2)
}
return val;
}
+ else if (code1 == TYPE_CODE_VOID)
+ {
+ return value_zero (type, not_lval);
+ }
else if (TYPE_LENGTH (type) == TYPE_LENGTH (type2))
{
if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
@@ -582,10 +586,6 @@ value_cast (struct type *type, struct value *arg2)
}
else if (VALUE_LVAL (arg2) == lval_memory)
return value_at_lazy (type, value_address (arg2));
- else if (code1 == TYPE_CODE_VOID)
- {
- return value_zero (type, not_lval);
- }
else
{
error (_("Invalid cast."));