This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

PR java/19277: Array.length++ is incorrectly allowed


Hi,

  The attached patch fixes PR java/19277. I've also attached
a testcase. Tested on i686-pc-linux-gnu, with Jacks included.

Ok for mainline?

Thanks,
Ranjit.

-- 
Ranjit Mathew      Email: rmathew AT gmail DOT com

Bangalore, INDIA.    Web: http://ranjitmathew.hostingzero.com/
Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	PR java/19277
	* check-init.c (check_init): Take care of references that do not
	have an explicit final variable declaration (e.g. array length
	access) for pre/post in/de-crement operators.

Index: check-init.c
===================================================================
--- check-init.c	2005-01-10 13:04:36.000000000 +0530
+++ check-init.c	2005-01-10 16:24:11.000000000 +0530
@@ -833,5 +833,11 @@ check_init (tree exp, words before)
       tmp = get_variable_decl (TREE_OPERAND (exp, 0));
       if (tmp != NULL_TREE && DECL_FINAL (tmp))
-	final_assign_error (DECL_NAME (tmp));      
+	final_assign_error (DECL_NAME (tmp));
+      else if (TREE_CODE (tmp = TREE_OPERAND (exp, 0)) == COMPONENT_REF)
+        {
+          tree decl = TREE_OPERAND (tmp, 1);
+          if (DECL_FINAL (decl))
+            final_assign_error (DECL_NAME (decl));
+        }
 
       /* Avoid needless recursion.  */
Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	* testsuite/libjava.compile/PR19277.java: New file for PR java/19277.
	* testsuite/libjava.compile/PR19277.xfail: Likewise.

Index: testsuite/libjava.compile/PR19277.java
===================================================================
--- testsuite/libjava.compile/PR19277.java	2005-01-10 15:40:57.000000000 +0530
+++ testsuite/libjava.compile/PR19277.java	2005-01-10 15:41:05.000000000 +0530
@@ -0,0 +1,7 @@
+class PR19277
+{
+  void snafu (int[] array)
+  {
+    array.length++;
+  }
+}
Index: testsuite/libjava.compile/PR19277.xfail
===================================================================
--- testsuite/libjava.compile/PR19277.xfail	2005-01-10 15:40:57.000000000 +0530
+++ testsuite/libjava.compile/PR19277.xfail	2005-01-10 15:41:23.000000000 +0530
@@ -0,0 +1 @@
+shouldfail

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