On Thu, Dec 27, 2018 at 12:54:30PM +0100, Dominique d'Humières wrote:
> Hi Steve,
> 
> The test gfortran.dg/pr81027.f90 succeeds without the patch.
> Would not it be better to replace
> 
> { dg-error "is not permitted in an" }
> 
> with something such as
> 
> { dg-error "Assumed-shape array" }
> 
> ?
> 
> Otherwise the patch works as expected.
> 
> Thank for the fix.
> 

For the record, here's the commit message and patch that I committed.

2018-12-27  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/81027
        * expr.c (gfc_check_init_expr): Distinguish assumed-shape versus
        deferred-shape dummy arguments in an error message.

2018-12-27  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/81027
        * gfortran.dg/pr81027.f90: New test.
        * gfortran.dg/initialization_7.f90: Update error message.
-- 
Steve
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 267435)
+++ gcc/fortran/expr.c	(working copy)
@@ -2869,9 +2869,16 @@ gfc_check_init_expr (gfc_expr *e)
 		break;
 
 	      case AS_DEFERRED:
-		gfc_error ("Deferred array %qs at %L is not permitted "
-			   "in an initialization expression",
-			   e->symtree->n.sym->name, &e->where);
+		if (!e->symtree->n.sym->attr.allocatable
+		    && !e->symtree->n.sym->attr.pointer
+		    && e->symtree->n.sym->attr.dummy)
+		  gfc_error ("Assumed-shape array %qs at %L is not permitted "
+			     "in an initialization expression",
+			     e->symtree->n.sym->name, &e->where);
+		else
+		  gfc_error ("Deferred array %qs at %L is not permitted "
+			     "in an initialization expression",
+			     e->symtree->n.sym->name, &e->where);
 		break;
 
 	      case AS_EXPLICIT:
Index: gcc/testsuite/gfortran.dg/pr81027.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr81027.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr81027.f90	(working copy)
@@ -0,0 +1,11 @@
+program badarray
+  implicit none
+  integer:: j(3) = [1,2,3]
+  call doubling(j)
+contains
+  subroutine doubling(  n)
+    integer,intent(in)::n(:)
+    integer::m = size(n)      ! { dg-error "Assumed-shape array" }
+    print *, m                ! { dg-error "has no IMPLICIT type" }
+  end subroutine doubling
+end program badarray
Index: gcc/testsuite/gfortran.dg/initialization_7.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_7.f90	(revision 267435)
+++ gcc/testsuite/gfortran.dg/initialization_7.f90	(working copy)
@@ -6,7 +6,7 @@
 
 subroutine probleme(p)
   real(kind=8), dimension(:) :: p
-  integer :: nx = size(p, 1)          ! { dg-error "Deferred array" }
+  integer :: nx = size(p, 1)          ! { dg-error "Assumed-shape array" }
   integer :: nix
 
   nix = nx

Reply via email to