[Bug fortran/56007] Remarkably bad error message with DO array=1,2

anlauf at gmx dot de gcc-bugzilla@gcc.gnu.org
Sun Feb 7 21:30:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56007

--- Comment #6 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Harald Anlauf from comment #5)
> The patch of comment #4 appears to be easily extendible to reject
> arrays as loop variables (I hope I got this right):
> 
> Index: gcc/fortran/match.c
> ===================================================================
> --- gcc/fortran/match.c (revision 232904)
> +++ gcc/fortran/match.c (working copy)
> @@ -877,6 +877,18 @@
>    if (m != MATCH_YES)
>      return MATCH_NO;
>  
> +  if (var->ts.type == BT_CHARACTER)
> +    {
> +      gfc_error ("Loop variable at %C cannot be of type CHARACTER");
> +      goto cleanup;
> +    }
> +
> +  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)
>      {

The first part of the patch is actually not needed, thus the essential
part is:

Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c (revision 232904)
+++ 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)
     {


This removed the most confusing error messages, but leaves those
cases untouched where the parsing of the do statement should give
a syntax error.

Testsuite suggestions based on Tobias' examples:

% cat pr56007.f
! { 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

% cat pr56007.f90
! { 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


More information about the Gcc-bugs mailing list