c-typeck.c (readonly_error): Improve error for assignment.

2007-08-09  Daniel Berlin  <dberlin@dberlin.org>

	* c-typeck.c (readonly_error): Improve error for assignment.
	
	* c-pretty-print.c (pp_c_additive_expression): Handle pointer-plus
	expression. 
	(pp_c_expression): Ditto.
2007-08-09  Daniel Berlin  <dberlin@dberlin.org>

	* typeck2.c (readonly_error): Handle general expressions.
	* error.c (dump_expr): Handle POINTER_PLUS_EXPR

From-SVN: r127320
This commit is contained in:
Daniel Berlin 2007-08-09 21:13:30 +00:00 committed by Daniel Berlin
parent d6bc05d4a4
commit d7705934ec
7 changed files with 37 additions and 6 deletions

View File

@ -1,3 +1,11 @@
2007-08-09 Daniel Berlin <dberlin@dberlin.org>
* c-typeck.c (readonly_error): Improve error for assignment.
* c-pretty-print.c (pp_c_additive_expression): Handle pointer-plus
expression.
(pp_c_expression): Ditto.
2007-08-09 Simon Baldwin <simonb@google.com>
* simplify-rtx.c (simplify_binary_operation_1): Removed erroneous

View File

@ -1597,11 +1597,12 @@ pp_c_additive_expression (c_pretty_printer *pp, tree e)
enum tree_code code = TREE_CODE (e);
switch (code)
{
case POINTER_PLUS_EXPR:
case PLUS_EXPR:
case MINUS_EXPR:
pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp);
if (code == PLUS_EXPR)
if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
pp_plus (pp);
else
pp_minus (pp);
@ -1979,6 +1980,7 @@ pp_c_expression (c_pretty_printer *pp, tree e)
pp_conditional_expression (pp, e);
break;
case POINTER_PLUS_EXPR:
case PLUS_EXPR:
case MINUS_EXPR:
pp_c_additive_expression (pp, e);

View File

@ -3152,10 +3152,11 @@ readonly_error (tree arg, enum lvalue_use use)
G_("read-only variable %qD used as %<asm%> output")),
arg);
else
error (READONLY_MSG (G_("assignment of read-only location"),
G_("increment of read-only location"),
G_("decrement of read-only location"),
G_("read-only location used as %<asm%> output")));
error (READONLY_MSG (G_("assignment of read-only location %qE"),
G_("increment of read-only location %qE"),
G_("decrement of read-only location %qE"),
G_("read-only location %qE used as %<asm%> output")),
arg);
}

View File

@ -1,3 +1,8 @@
2007-08-09 Daniel Berlin <dberlin@dberlin.org>
* typeck2.c (readonly_error): Handle general expressions.
* error.c (dump_expr): Handle POINTER_PLUS_EXPR
2007-08-06 Dan Hipschman <dsh@google.com>
* method.c (use_thunk): Use DECL_NAME instead of DECL_RTL to

View File

@ -1612,6 +1612,10 @@ dump_expr (tree t, int flags)
dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
break;
case POINTER_PLUS_EXPR:
dump_binary_op ("+", t, flags);
break;
case INIT_EXPR:
case MODIFY_EXPR:
case PLUS_EXPR:

View File

@ -104,7 +104,7 @@ readonly_error (tree arg, const char* string)
else if (TREE_CODE (arg) == FUNCTION_DECL)
error ("%s of function %qD", string, arg);
else
error ("%s of read-only location", string);
error ("%s of read-only location %qE", string, arg);
}

View File

@ -0,0 +1,11 @@
/* { dg-do compile } */
/* { dg-options "-O" } */
int func()
{
const int *arr;
const int arr2[5];
arr[0] = 1; /* { dg-error "assignment of read-only location" "*(arr)" } */
arr[1] = 1; /* { dg-error "assignment of read-only location" "*(arr + 4u)" } */
arr2[0] = 1; /* { dg-error "assignment of read-only location" "arr2\[0\]" } */
arr2[1] = 1; /* { dg-error "assignment of read-only location" "arr2\[1\]" } */
}