diff options
author | Pedro Alves <palves@redhat.com> | 2010-02-11 21:45:25 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2010-02-11 21:45:25 +0000 |
commit | be636754b785aa5b042991267c851af18ed5b6a9 (patch) | |
tree | 47af6d7426102b5b75f722530ba4b0d5deb96839 /gdb/ax-gdb.c | |
parent | 10ef8d6a8dfca5731b2f4eb4dec945a299050e3c (diff) | |
download | gdb-be636754b785aa5b042991267c851af18ed5b6a9.zip gdb-be636754b785aa5b042991267c851af18ed5b6a9.tar.gz gdb-be636754b785aa5b042991267c851af18ed5b6a9.tar.bz2 |
* ax-gdb.c (gen_exp_binop_rest) [BINOP_SUBSCRIPT]: Error out on
non-subscriptable types.
* valarith.c (binop_types_user_defined_p): New, abstracted out
from ...
(binop_user_defined_p): ... this.
* value.h (binop_types_user_defined_p): Declare.
Diffstat (limited to 'gdb/ax-gdb.c')
-rw-r--r-- | gdb/ax-gdb.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index eb53238..75aa7ca6 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -1885,11 +1885,35 @@ gen_expr_binop_rest (struct expression *exp, aop_rem_signed, aop_rem_unsigned, 1, "remainder"); break; case BINOP_SUBSCRIPT: - gen_ptradd (ax, value, value1, value2); - if (!pointer_type (value->type)) - error (_("Invalid combination of types in array subscripting.")); - gen_deref (ax, value); - break; + { + struct type *type; + + if (binop_types_user_defined_p (op, value1->type, value2->type)) + { + error (_("\ +cannot subscript requested type: cannot call user defined functions")); + } + else + { + /* If the user attempts to subscript something that is not + an array or pointer type (like a plain int variable for + example), then report this as an error. */ + type = check_typedef (value1->type); + if (TYPE_CODE (type) != TYPE_CODE_ARRAY + && TYPE_CODE (type) != TYPE_CODE_PTR) + { + if (TYPE_NAME (type)) + error (_("cannot subscript something of type `%s'"), + TYPE_NAME (type)); + else + error (_("cannot subscript requested type")); + } + } + + gen_ptradd (ax, value, value1, value2); + gen_deref (ax, value); + break; + } case BINOP_BITWISE_AND: gen_binop (ax, value, value1, value2, aop_bit_and, aop_bit_and, 0, "bitwise and"); |