* [patch, fortran] PR32906 - Parameter array ... cannot be automatic or assumed shape
@ 2007-07-26 22:35 Daniel Franke
2007-07-29 13:40 ` Paul Thomas
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Franke @ 2007-07-26 22:35 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]
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
[-- Attachment #2: pr32906.patch --]
[-- Type: text/x-diff, Size: 2148 bytes --]
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch, fortran] PR32906 - Parameter array ... cannot be automatic or assumed shape
2007-07-26 22:35 [patch, fortran] PR32906 - Parameter array ... cannot be automatic or assumed shape Daniel Franke
@ 2007-07-29 13:40 ` Paul Thomas
0 siblings, 0 replies; 2+ messages in thread
From: Paul Thomas @ 2007-07-29 13:40 UTC (permalink / raw)
To: Daniel Franke; +Cc: fortran, gcc-patches
Daniel,
Since I had a hand in the original, it's only fitting that I....
>
> Regression tested on i686-pc-linux-gnu. Ok for trunk?
>
....OK the correction:)
Could you add ADDPATCH fortran to the top of your submissions, please?
It triggers off the automatic patch tracking.
Thanks
Paul
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-07-29 13:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-26 22:35 [patch, fortran] PR32906 - Parameter array ... cannot be automatic or assumed shape Daniel Franke
2007-07-29 13:40 ` Paul Thomas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).