]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran - correct check for constraint F2008:C628 / F2018:C932
authorHarald Anlauf <anlauf@gmx.de>
Mon, 30 Aug 2021 20:41:01 +0000 (22:41 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 30 Aug 2021 20:41:01 +0000 (22:41 +0200)
gcc/fortran/ChangeLog:

PR fortran/101349
* resolve.c (resolve_allocate_expr): An unlimited polymorphic
argument to ALLOCATE must be ALLOCATABLE or a POINTER.  Fix the
corresponding check.

gcc/testsuite/ChangeLog:

PR fortran/101349
* gfortran.dg/unlimited_polymorphic_33.f90: New test.

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/unlimited_polymorphic_33.f90 [new file with mode: 0644]

index f641d0d4dae01e1f00d58911b1e58a719bda7a38..d7aa2868cef7a132a08421e5a10fe3633d7cc16e 100644 (file)
@@ -7829,8 +7829,9 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec)
        }
     }
 
-  /* Check for F08:C628.  */
-  if (allocatable == 0 && pointer == 0 && !unlimited)
+  /* Check for F08:C628 (F2018:C932).  Each allocate-object shall be a data
+     pointer or an allocatable variable.  */
+  if (allocatable == 0 && pointer == 0)
     {
       gfc_error ("Allocate-object at %L must be ALLOCATABLE or a POINTER",
                 &e->where);
diff --git a/gcc/testsuite/gfortran.dg/unlimited_polymorphic_33.f90 b/gcc/testsuite/gfortran.dg/unlimited_polymorphic_33.f90
new file mode 100644 (file)
index 0000000..8bb8864
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! PR fortran/101349 - ICE in gfc_get_descriptor_field
+! Check constraint F2008:C628 / F2018:C932
+
+subroutine s(x)
+  class(*) :: x(:)
+  allocate (x, source=['abc']) ! { dg-error "must be ALLOCATABLE or a POINTER" }
+end
+
+subroutine t(x)
+  class(*), allocatable :: x(:)
+  allocate (x, source=['abc'])
+end
+
+subroutine u(x)
+  class(*), pointer :: x(:)
+  allocate (x, source=['abc'])
+end