This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: increment or decrement of final variables


Jacks pointed out that gcj currently incorrectly compiles this
program:

    class T15152a9 {
	final int i = 1, j = ++i;
    }

It doesn't make sense to use ++ or -- on a final variable.
This patch fixes the problem.  I also took the opportunity to reword
the error message.

Ok?

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* check-init.c (check_init): Don't allow pre- or post- increment
	or decrement of final variable.
	(final_assign_error): Minor error message rewording.

Index: check-init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/check-init.c,v
retrieving revision 1.37
diff -u -r1.37 check-init.c
--- check-init.c 2001/12/07 18:16:21 1.37
+++ check-init.c 2001/12/09 05:34:50
@@ -196,7 +196,7 @@
      tree name;
 {
   static const char format[]
-    = "can't re-assign here a value to the final variable '%s'";
+    = "can't reassign a value to the final variable '%s'";
   parse_error_context (wfl, format, IDENTIFIER_POINTER (name));
 }
 
@@ -791,10 +791,6 @@
     case FIX_TRUNC_EXPR:
     case INDIRECT_REF:
     case ADDR_EXPR:
-    case PREDECREMENT_EXPR:
-    case PREINCREMENT_EXPR:
-    case POSTDECREMENT_EXPR:
-    case POSTINCREMENT_EXPR:
     case NON_LVALUE_EXPR:
     case INSTANCEOF_EXPR:
     case FIX_CEIL_EXPR:
@@ -803,6 +799,18 @@
     case ABS_EXPR:
     case FFS_EXPR:
       /* Avoid needless recursion. */
+      exp = TREE_OPERAND (exp, 0);
+      goto again;
+
+    case PREDECREMENT_EXPR:
+    case PREINCREMENT_EXPR:
+    case POSTDECREMENT_EXPR:
+    case POSTINCREMENT_EXPR:
+      tmp = get_variable_decl (TREE_OPERAND (exp, 0));
+      if (tmp != NULL_TREE && DECL_FINAL (tmp))
+	final_assign_error (DECL_NAME (tmp));      
+
+      /* Avoid needless recursion.  */
       exp = TREE_OPERAND (exp, 0);
       goto again;
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]