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

            Bug ID: 102180
           Summary: Improve checking of assume size array spec
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

F2018 has:

8.5.8.5  Assumed-size array

R821 assumed-implied-spec  is  [ lower-bound : ] *


We currently give a misleading error message for:

subroutine s(x)
  real :: x(0:*) ! legal
end

subroutine t(x)
  real :: x(:*) ! illegal
end


uuu.f90:6:14:

    6 |   real :: x(:*) ! illegal
      |              1
Error: Expected another dimension in array declaration at (1)


A possibly better error message could be:

uuu.f90:6:15:

    6 |   real :: x(:*) ! illegal
      |               1
Error: A lower bound must precede colon in assumed size array specification at
(1)

which is obtained by the patch:

diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index b858bada18a..56d26455972 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -481,6 +481,13 @@ match_array_element_spec (gfc_array_spec *as)
       return AS_ASSUMED_SIZE;
     }

+  if (gfc_match (" : * ") == MATCH_YES)
+    {
+      gfc_error ("A lower bound must precede colon in "
+                "assumed size array specification at %C");
+      return AS_UNKNOWN;
+    }
+
   if (gfc_match_char (':') == MATCH_YES)
     return AS_DEFERRED;


This might be important for some other PRs, as this affects the return value
of match_array_element_spec.  This is also potentially relevant for illegal
coarray specs, such as

  integer :: a[1:,:*]

where match_array_element_spec currently returns AS_DEFERRED for a badly
specified dimension.

Reply via email to