diagnostic.c (error_at): New.
* diagnostic.c (error_at): New. * toplev.h (error_at): New prototype. * c-typeck.c (build_array_ref): Call error_at instead of error. Pass location to pedwarn. cp/ * 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. From-SVN: r139924
This commit is contained in:
parent
aeb76a25a7
commit
a63068b6dd
10 changed files with 73 additions and 30 deletions
|
@ -1,3 +1,10 @@
|
|||
2008-09-02 Aldy Hernandez <aldyh@redhat.com>
|
||||
|
||||
* diagnostic.c (error_at): New.
|
||||
* toplev.h (error_at): New prototype.
|
||||
* c-typeck.c (build_array_ref): Call error_at instead of error.
|
||||
Pass location to pedwarn.
|
||||
|
||||
2008-09-02 Adam Nemet <anemet@caviumnetworks.com>
|
||||
|
||||
* sel-sched.c (sel_hard_regno_rename_ok): Mark arguments unused.
|
||||
|
|
|
@ -2061,7 +2061,7 @@ build_array_ref (tree array, tree index, location_t loc)
|
|||
if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
|
||||
&& TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
|
||||
{
|
||||
error ("subscripted value is neither array nor pointer");
|
||||
error_at (loc, "subscripted value is neither array nor pointer");
|
||||
return error_mark_node;
|
||||
}
|
||||
temp = array;
|
||||
|
@ -2072,13 +2072,13 @@ build_array_ref (tree array, tree index, location_t loc)
|
|||
|
||||
if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
|
||||
{
|
||||
error ("array subscript is not an integer");
|
||||
error_at (loc, "array subscript is not an integer");
|
||||
return error_mark_node;
|
||||
}
|
||||
|
||||
if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
|
||||
{
|
||||
error ("subscripted value is pointer to function");
|
||||
error_at (loc, "subscripted value is pointer to function");
|
||||
return error_mark_node;
|
||||
}
|
||||
|
||||
|
@ -2125,10 +2125,10 @@ build_array_ref (tree array, tree index, location_t loc)
|
|||
while (TREE_CODE (foo) == COMPONENT_REF)
|
||||
foo = TREE_OPERAND (foo, 0);
|
||||
if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
|
||||
pedwarn (input_location, OPT_pedantic,
|
||||
pedwarn (loc, OPT_pedantic,
|
||||
"ISO C forbids subscripting %<register%> array");
|
||||
else if (!flag_isoc99 && !lvalue_p (foo))
|
||||
pedwarn (input_location, OPT_pedantic,
|
||||
pedwarn (loc, OPT_pedantic,
|
||||
"ISO C90 forbids subscripting non-lvalue array");
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -598,6 +598,19 @@ error (const char *gmsgid, ...)
|
|||
va_end (ap);
|
||||
}
|
||||
|
||||
/* Same as ebove, but use location LOC instead of input_location. */
|
||||
void
|
||||
error_at (location_t loc, const char *gmsgid, ...)
|
||||
{
|
||||
diagnostic_info diagnostic;
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, gmsgid);
|
||||
diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
|
||||
report_diagnostic (&diagnostic);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
/* "Sorry, not implemented." Use for a language feature which is
|
||||
required by the relevant specification but not implemented by GCC.
|
||||
An object file will not be produced. */
|
||||
|
|
|
@ -61,6 +61,7 @@ extern bool warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
|
|||
extern bool warning_at (location_t, int, const char *, ...)
|
||||
ATTRIBUTE_GCC_DIAG(3,4);
|
||||
extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
|
||||
extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
|
||||
extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
|
||||
ATTRIBUTE_NORETURN;
|
||||
/* Pass one of the OPT_W* from options.h as the second parameter. */
|
||||
|
|
Loading…
Add table
Reference in a new issue