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]

[patch, fortran] PR32906 - Parameter array ... cannot be automatic or assumed shape


This seems to be a 2-in-1: not only the error was unjustified, but the message 
was also incorrectly worded. Consider

   integer, parameter :: len = 1
   integer, parameter :: arr(max(len,1)) = (/1/)
   end

where gfortran complains:
   Parameter array 'arr' at (1) cannot be automatic or assumed shape

As an assumed shape array is a "nonpointer dummy argument array" (5.1.2.4.2), 
parameter arrays can not be of assumed shape as dummy arguments are not 
allowed to have the parameter attribute (5.1, constraint of R503). Instead, 
arrays of deferred shape, i.e. an "allocatable array or an array pointer" 
(5.1.2.4.3), must be rejected (see also gfortran.dg/shape_1.f90). 

Acoordingly, the test for parameter arrays as well as the error message was 
adjusted to fix these problems.


gcc/fortran:
2007-07-26  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/32906
	* resolve.c (resolve_fl_parameter): Check for constant shape arrays, 
	adjusted error message.

gcc/testsuite:
2007-07-26  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/32906
	* gfortran.dg/shape_1.f90: Adjust error message.
	* gfortran.dg/parameter_array_ref_1.f90: New test.


Regression tested on i686-pc-linux-gnu. Ok for trunk?

Regards
	Daniel

Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c	(revision 126930)
+++ fortran/resolve.c	(working copy)
@@ -7098,10 +7112,12 @@
 resolve_fl_parameter (gfc_symbol *sym)
 {
   /* A parameter array's shape needs to be constant.  */
-  if (sym->as != NULL && !gfc_is_compile_time_shape (sym->as))
+  if (sym->as != NULL 
+      && (sym->as->type == AS_DEFERRED
+          || is_non_constant_shape_array (sym)))
     {
       gfc_error ("Parameter array '%s' at %L cannot be automatic "
-		 "or assumed shape", sym->name, &sym->declared_at);
+		 "or of deferred shape", sym->name, &sym->declared_at);
       return FAILURE;
     }
 
Index: testsuite/gfortran.dg/shape_1.f90
===================================================================
--- testsuite/gfortran.dg/shape_1.f90	(revision 126930)
+++ testsuite/gfortran.dg/shape_1.f90	(working copy)
@@ -1,6 +1,6 @@
 ! { dg-do compile }
 ! PR 13201 we used to not give an error in those cases
 subroutine foo(n) 
-  integer, parameter :: a(n) = 1 ! { dg-error "cannot be automatic" "automatic shape" }
-  integer, parameter :: z(:) = (/ 1,2,3 /) ! { dg-error "cannot be automatic" "assumed shape" }
+  integer, parameter :: a(n) = 1           ! { dg-error "cannot be automatic" "automatic shape" }
+  integer, parameter :: z(:) = (/ 1,2,3 /) ! { dg-error "cannot be automatic" "deferred shape" }
 end subroutine
Index: testsuite/gfortran.dg/parameter_array_ref_1.f90
===================================================================
--- testsuite/gfortran.dg/parameter_array_ref_1.f90	(revision 0)
+++ testsuite/gfortran.dg/parameter_array_ref_1.f90	(revision 0)
@@ -0,0 +1,13 @@
+! { dg-do compile }
+!
+! PR fortran/32906 - Parameter array ... cannot be automatic or assumed shape
+!
+! Testcase contributed by Florian Ladstaedter <flad AT gmx DOT at>
+!
+program test_program
+  integer, parameter :: len = 1
+  integer, parameter :: arr(max(len,1)) = (/1/)
+
+  character(len=*), dimension (1), parameter             :: specStr = (/'string'/)
+  double precision, dimension (size(specStr)), parameter :: specNum = (/99.0d0/)
+end

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