From 0ba2eb0fb60577c618e188ff4a879a721199395d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 6 Dec 2012 21:41:07 +0000 Subject: [PATCH] 2012-12-06 Pedro Alves Tom Tromey * valops.c (value_cast): Move TYPE_CODE_VOID case earlier. testsuite * gdb.base/exprs.exp: Add tests for cast to void. --- gdb/ChangeLog | 5 +++++ gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.base/exprs.exp | 4 ++++ gdb/valops.c | 8 ++++---- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4f89004a953..7f9ca8fe356 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2012-12-06 Pedro Alves + Tom Tromey + + * valops.c (value_cast): Move TYPE_CODE_VOID case earlier. + 2012-12-06 Jens Elmenthaler PR mi/14741: diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f05cd87916a..335ecff6149 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-12-06 Pedro Alves + Tom Tromey + + * gdb.base/exprs.exp: Add tests for cast to void. + 2012-12-06 Jens Elmenthaler * gdb.python/py-mi.exp: Correct expected results for attribute diff --git a/gdb/testsuite/gdb.base/exprs.exp b/gdb/testsuite/gdb.base/exprs.exp index c6a07fa4773..f3de09e1b9b 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 1dd25799bfc..372f1186eeb 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.")); -- 2.30.2