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

            Bug ID: 101951
           Summary: Implement F2018:C937
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kargl at gcc dot gnu.org
  Target Milestone: ---

A small program was posted by Vipul Parekh in the J3
mailing list asking about its conformance.

https://mailman.j3-fortran.org/pipermail/j3/2021-August/013230.html

The program exposes a bug where gfortran was not
handling F2018:C937 (R927) (same as F2008:C640 (R626)).

This patch fixes this problem and I've dejagnu-ified the
test program.

diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 16502da001d..b1a2ac5384a 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -4233,7 +4233,7 @@ gfc_match_allocate (void)

       if (gfc_match (" :: ") == MATCH_YES)
        {
-         if (!gfc_notify_std (GFC_STD_F2003, "typespec in ALLOCATE at %L",
+         if (!gfc_notify_std (GFC_STD_F2003, "type-spec in ALLOCATE at %L",
                               &old_locus))
            goto cleanup;

@@ -4266,6 +4266,16 @@ gfc_match_allocate (void)
          ts.type = BT_UNKNOWN;
          gfc_current_locus = old_locus;
        }
+
+      /* F2018:C937 (R927) type-spec shall not specify a type that has a
+        coarray ultimate component.  Similar text in F2008:C640 (R626).  */
+      if (ts.type == BT_DERIVED
+         && ts.u.derived->attr.coarray_comp)
+       {
+         gfc_error ("Type-spec at %L has a coarray ultimate component",
+                    &old_locus);
+         goto cleanup;
+       }
     }

   for (;;)
diff --git a/gcc/testsuite/gfortran.dg/f2018c937.f90
b/gcc/testsuite/gfortran.dg/f2018c937.f90
new file mode 100644
index 00000000000..2a789a0e2d2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/f2018c937.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+! https://mailman.j3-fortran.org/pipermail/j3/2021-August/013230.html
+program foo
+   type :: a_t
+      integer, allocatable :: n[:]
+   end type
+   class(*), allocatable :: a
+   allocate(a_t :: a)         ! { dg-error "coarray ultimate component" }
+end program foo

Reply via email to