This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] PR34514 - prevent double initialization and dimension changes after initialization
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>
- Date: Mon, 17 Dec 2007 21:22:41 +0100
- Subject: [Patch, Fortran] PR34514 - prevent double initialization and dimension changes after initialization
It is completely unclear what value "n" has after:
integer :: n = 4
dimension :: n(3)
similarly invalid is:
integer :: n = 5
parameter (n = 7)
This patch adds checks to reject this.
Please try to come up with things which should be rejected; I think
there are none, but I still might have missed something. ;-)
Build and regtested on x86-64. OK for the trunk?
Tobias
PS: I did not check the standard, but ifort and NAG f95 reject it. As it
makes sense, I believe these compilers. If needed be, I can still try to
find it in the standard.
2007-12-17 Tobias Burnus <burnus@net-b.de>
PR fortran/34514
* decl.c (attr_decl1): Reject specifying the DIMENSION for
already initialized variable.
(do_parm): Reject PARAMETER for already initialized variable.
2007-12-17 Tobias Burnus <burnus@net-b.de>
PR fortran/34514
* gfortran.dg/initialization_17.f90: New.
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c (revision 131009)
+++ gcc/fortran/decl.c (working copy)
@@ -5151,6 +5151,14 @@ attr_decl1 (void)
goto cleanup;
}
+ if (current_attr.dimension && sym->value)
+ {
+ gfc_error ("Dimensions specified for %s at %L after its "
+ "initialisation", sym->name, &var_locus);
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+
if ((current_attr.allocatable || current_attr.pointer)
&& (m == MATCH_YES) && (as->type != AS_DEFERRED))
{
@@ -5753,6 +5761,13 @@ do_parm (void)
goto cleanup;
}
+ if (sym->value)
+ {
+ gfc_error ("Initializing already initialized variable at %C");
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+
if (sym->ts.type == BT_CHARACTER
&& sym->ts.cl != NULL
&& sym->ts.cl->length != NULL
Index: gcc/testsuite/gfortran.dg/initialization_17.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_17.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/initialization_17.f90 (revision 0)
@@ -0,0 +1,10 @@
+! { dg-do compile }
+!
+! PR fortran/34514
+!
+! Initialization and typespec changes.
+!
+integer :: n = 5, m = 7
+parameter (n = 42) ! { dg-error "Initializing already initialized variable" }
+dimension :: m(3) ! { dg-error "after its initialisation" }
+end