diff mbox

[fortran] PR56007 Remarkably bad error message with DO array=1,2

Message ID 56B8EC47.4040908@gmx.de
State New
Headers show

Commit Message

Harald Anlauf Feb. 8, 2016, 7:28 p.m. UTC
Hi,

the simple patch below rejects arrays as do loop index
variable before another (confusing) error message is emitted.
Two new testcases derived from the PR, plus adaption of one
testcase that relies on the old error message.

Whoever wants to take it...

Harald


2016-02-08  Harald Anlauf <anlauf@gmx.de>

	PR fortran/56007
	* match.c (gfc_match_iterator): Add diagnostic for array variable
	as do loop index.

Comments

Jerry DeLisle Feb. 10, 2016, 2:49 a.m. UTC | #1
On 02/08/2016 11:28 AM, Harald Anlauf wrote:
> Hi,
> 
> the simple patch below rejects arrays as do loop index
> variable before another (confusing) error message is emitted.
> Two new testcases derived from the PR, plus adaption of one
> testcase that relies on the old error message.
> 
> Whoever wants to take it...
> 

I will commit this under the simple rules as soon as I get the namelist
regression fix committed on trunk.

Thanks Harald

Jerry
diff mbox

Patch

Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c	(revision 233203)
+++ gcc/fortran/match.c	(working copy)
@@ -877,6 +877,12 @@ 
   if (m != MATCH_YES)
     return MATCH_NO;

+  if (var->symtree->n.sym->attr.dimension)
+    {
+      gfc_error ("Loop variable at %C cannot be an array");
+      goto cleanup;
+    }
+
   /* F2008, C617 & C565.  */
   if (var->symtree->n.sym->attr.codimension)
     {


2016-02-08  Harald Anlauf <anlauf@gmx.de>

	PR fortran/56007
	* gfortran.dg/coarray_8.f90: Adjust error message.
	* gfortran.dg/pr56007.f90: New test.
	* gfortran.dg/pr56007.f: New test.

Index: gcc/testsuite/gfortran.dg/coarray_8.f90
===================================================================
--- gcc/testsuite/gfortran.dg/coarray_8.f90	(revision 233203)
+++ gcc/testsuite/gfortran.dg/coarray_8.f90	(working copy)
@@ -146,7 +146,7 @@ 
 subroutine tfgh()
   integer :: i(2)
   DATA i/(i, i=1,2)/ ! { dg-error "Expected PARAMETER symbol" }
-  do i = 1, 5 ! { dg-error "cannot be a sub-component" }
+  do i = 1, 5 ! { dg-error "cannot be an array" }
   end do ! { dg-error "Expecting END SUBROUTINE" }
 end subroutine tfgh

Index: gcc/testsuite/gfortran.dg/pr56007.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr56007.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr56007.f90	(revision 0)
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! PR fortran/56007
+! Based on testcase by Tobias Schlüter
+
+  integer iw1(90), doiw1(90)
+  do iw1=1,2     ! { dg-error "cannot be an array" }
+  end do         ! { dg-error "Expecting END PROGRAM statement" }
+  do iw1(1)=1    ! { dg-error "Unclassifiable statement" }
+  do iw1=1       ! { dg-error "cannot be an array" }
+  end do         ! { dg-error "Expecting END PROGRAM statement" }
+END program
Index: gcc/testsuite/gfortran.dg/pr56007.f
===================================================================
--- gcc/testsuite/gfortran.dg/pr56007.f	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr56007.f	(revision 0)
@@ -0,0 +1,10 @@ 
+! { dg-do compile }
+! PR fortran/56007
+! Based on testcase by Tobias Schlüter
+
+      integer iw1(90), doiw1(90)
+      do iw1(1)=1
+      do iw1=1
+      do iw1=1,2    ! { dg-error "cannot be an array" }
+      end do        ! { dg-error "Expecting END PROGRAM statement" }
+      END