public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran] PR34514 - prevent double initialization and dimension  changes after initialization
@ 2007-12-17 20:31 Tobias Burnus
  2007-12-24 14:35 ` Tobias Burnus
  2007-12-24 16:31 ` Jerry DeLisle
  0 siblings, 2 replies; 3+ messages in thread
From: Tobias Burnus @ 2007-12-17 20:31 UTC (permalink / raw)
  To: gcc-patches, 'fortran@gcc.gnu.org'

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

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.

[-- Attachment #2: init.diff --]
[-- Type: text/plain, Size: 1747 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, Fortran] PR34514 - prevent double initialization and  dimension  changes after initialization
  2007-12-17 20:31 [Patch, Fortran] PR34514 - prevent double initialization and dimension changes after initialization Tobias Burnus
@ 2007-12-24 14:35 ` Tobias Burnus
  2007-12-24 16:31 ` Jerry DeLisle
  1 sibling, 0 replies; 3+ messages in thread
From: Tobias Burnus @ 2007-12-24 14:35 UTC (permalink / raw)
  To: gcc-patches, 'fortran@gcc.gnu.org'

*PING*
http://gcc.gnu.org/ml/fortran/2007-12/msg00221.html

Tobias Burnus wrote:
> 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.
>   
[...]
> Build and regtested on x86-64. OK for the trunk?
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch, Fortran] PR34514 - prevent double initialization and  dimension  changes after initialization
  2007-12-17 20:31 [Patch, Fortran] PR34514 - prevent double initialization and dimension changes after initialization Tobias Burnus
  2007-12-24 14:35 ` Tobias Burnus
@ 2007-12-24 16:31 ` Jerry DeLisle
  1 sibling, 0 replies; 3+ messages in thread
From: Jerry DeLisle @ 2007-12-24 16:31 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'

Tobias Burnus wrote:
> 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.
> 
OK to commit

Jerry

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-24 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-17 20:31 [Patch, Fortran] PR34514 - prevent double initialization and dimension changes after initialization Tobias Burnus
2007-12-24 14:35 ` Tobias Burnus
2007-12-24 16:31 ` Jerry DeLisle

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).