This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR fortran/81027 -- Issue error for assumed-shape array


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  <kargl@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  <kargl@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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]