diff options
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/call.c | 2 | ||||
-rw-r--r-- | gcc/cp/class.c | 2 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 2 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 56 |
6 files changed, 47 insertions, 25 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 67f3f2b7b04..c5ccb40b402 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2008-09-02 Aldy Hernandez <aldyh@redhat.com> + + * typeck.c (build_array_ref): Use new location argument. + * class.c (build_vtbl_ref_1): Pass location to build_array_ref. + * call.c (build_new_op): Same. + * decl2.c (grok_array_decl): Same. + * cp-tree.h (build_array_ref): Add location argument to prototype. + 2008-09-01 Aldy Hernandez <aldyh@redhat.com> * typeck.c (build_x_indirect_ref): Add location argument. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 6a6c2c25c18..571f36fb70d 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4214,7 +4214,7 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, return cp_build_unary_op (code, arg1, candidates != 0, complain); case ARRAY_REF: - return build_array_ref (arg1, arg2); + return build_array_ref (arg1, arg2, input_location); case COND_EXPR: return build_conditional_expr (arg1, arg2, arg3, complain); diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 5f7d4a28c9d..4f69c7e776a 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -627,7 +627,7 @@ build_vtbl_ref_1 (tree instance, tree idx) assemble_external (vtbl); - aref = build_array_ref (vtbl, idx); + aref = build_array_ref (vtbl, idx, input_location); TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx); return aref; diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a01d981f9f9..09b3b2f4033 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4911,7 +4911,7 @@ extern tree build_x_indirect_ref (tree, const char *, tsubst_flags_t); extern tree cp_build_indirect_ref (tree, const char *, tsubst_flags_t); -extern tree build_array_ref (tree, tree); +extern tree build_array_ref (tree, tree, location_t); extern tree get_member_function_from_ptrfunc (tree *, tree); extern tree cp_build_function_call (tree, tree, tsubst_flags_t); extern tree build_x_binary_op (enum tree_code, tree, diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 677597ec422..0e56c070456 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -354,7 +354,7 @@ grok_array_decl (tree array_expr, tree index_exp) if (array_expr == error_mark_node || index_exp == error_mark_node) error ("ambiguous conversion for array subscript"); - expr = build_array_ref (array_expr, index_exp); + expr = build_array_ref (array_expr, index_exp, input_location); } if (processing_template_decl && expr != error_mark_node) return build_min_non_dep (ARRAY_REF, expr, orig_array_expr, orig_index_exp, diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index d60ddbd950b..9de51c53c16 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2506,14 +2506,18 @@ cp_build_indirect_ref (tree ptr, const char *errorstring, If INDEX is of some user-defined type, it must be converted to integer type. Otherwise, to make a compatible PLUS_EXPR, it - will inherit the type of the array, which will be some pointer type. */ + will inherit the type of the array, which will be some pointer type. + + LOC is the location to use in building the array reference. */ tree -build_array_ref (tree array, tree idx) +build_array_ref (tree array, tree idx, location_t loc) { + tree ret; + if (idx == 0) { - error ("subscript missing in array reference"); + error_at (loc, "subscript missing in array reference"); return error_mark_node; } @@ -2527,17 +2531,21 @@ build_array_ref (tree array, tree idx) { case COMPOUND_EXPR: { - tree value = build_array_ref (TREE_OPERAND (array, 1), idx); - return build2 (COMPOUND_EXPR, TREE_TYPE (value), - TREE_OPERAND (array, 0), value); + tree value = build_array_ref (TREE_OPERAND (array, 1), idx, loc); + ret = build2 (COMPOUND_EXPR, TREE_TYPE (value), + TREE_OPERAND (array, 0), value); + SET_EXPR_LOCATION (ret, loc); + return ret; } case COND_EXPR: - return build_conditional_expr - (TREE_OPERAND (array, 0), - build_array_ref (TREE_OPERAND (array, 1), idx), - build_array_ref (TREE_OPERAND (array, 2), idx), - tf_warning_or_error); + ret = build_conditional_expr + (TREE_OPERAND (array, 0), + build_array_ref (TREE_OPERAND (array, 1), idx, loc), + build_array_ref (TREE_OPERAND (array, 2), idx, loc), + tf_warning_or_error); + SET_EXPR_LOCATION (ret, loc); + return ret; default: break; @@ -2551,7 +2559,7 @@ build_array_ref (tree array, tree idx) if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx))) { - error ("array subscript is not an integer"); + error_at (loc, "array subscript is not an integer"); return error_mark_node; } @@ -2588,7 +2596,8 @@ build_array_ref (tree array, tree idx) } if (!lvalue_p (array)) - pedwarn (input_location, OPT_pedantic, "ISO C++ forbids subscripting non-lvalue array"); + pedwarn (loc, OPT_pedantic, + "ISO C++ forbids subscripting non-lvalue array"); /* Note in C++ it is valid to subscript a `register' array, since it is valid to take the address of something with that @@ -2599,7 +2608,8 @@ build_array_ref (tree array, tree idx) while (TREE_CODE (foo) == COMPONENT_REF) foo = TREE_OPERAND (foo, 0); if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo)) - warning (OPT_Wextra, "subscripting array declared %<register%>"); + warning_at (loc, OPT_Wextra, + "subscripting array declared %<register%>"); } type = TREE_TYPE (TREE_TYPE (array)); @@ -2612,7 +2622,9 @@ build_array_ref (tree array, tree idx) |= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array)); TREE_THIS_VOLATILE (rval) |= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array)); - return require_complete_type (fold_if_not_in_template (rval)); + ret = require_complete_type (fold_if_not_in_template (rval)); + SET_EXPR_LOCATION (ret, loc); + return ret; } { @@ -2632,21 +2644,23 @@ build_array_ref (tree array, tree idx) if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE) { - error ("subscripted value is neither array nor pointer"); + error_at (loc, "subscripted value is neither array nor pointer"); return error_mark_node; } if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE) { - error ("array subscript is not an integer"); + error_at (loc, "array subscript is not an integer"); return error_mark_node; } warn_array_subscript_with_type_char (idx); - return cp_build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind, - tf_warning_or_error), - "array indexing", - tf_warning_or_error); + ret = cp_build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind, + tf_warning_or_error), + "array indexing", + tf_warning_or_error); + protected_set_expr_location (ret, loc); + return ret; } } |