2007-08-09 Daniel Berlin <dberlin@dberlin.org>
authordberlin <dberlin@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Aug 2007 21:13:30 +0000 (21:13 +0000)
committerdberlin <dberlin@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 9 Aug 2007 21:13:30 +0000 (21:13 +0000)
* 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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@127320 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-pretty-print.c
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/cp/typeck2.c
gcc/testsuite/gcc.dg/readonly-loc.c [new file with mode: 0644]

index b6c953a..f9cfb2e 100644 (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
index e11d83c..a5dd82f 100644 (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);
index e54eedb..3e209e2 100644 (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);
 }
 
 
index e656382..e4fcf64 100644 (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
index 4e34f04..46785f9 100644 (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:
index 215e1a3..f1c3c32 100644 (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);
 }
 
 \f
diff --git a/gcc/testsuite/gcc.dg/readonly-loc.c b/gcc/testsuite/gcc.dg/readonly-loc.c
new file mode 100644 (file)
index 0000000..c5d1c97
--- /dev/null
@@ -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\]" } */
+}