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]

[fortran, patch] PR34402, accepts invalid init expr


Hi all,

there's a condition on initialization expressions, that allocatable components 
shall not be initialized with data but NULL(). Attached patch adds a check for 
this. The testcase is the reporter's.

The wording of the error message is a bit awkward and longish, any other 
suggestions?


2009-12-10  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/34402
	* expr.c (check_alloc_comp_init): New.
	(check_init_expr): Verify that allocatable components are not
	data-initalized.

2009-12-10  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/34402
	* gfortran.dg/alloc_comp_init_expr.f03: New.


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

Cheers

	Daniel

Attachment: alloc_comp_init_expr.f03
Description: Text document

Index: expr.c
===================================================================
--- expr.c	(revision 155121)
+++ expr.c	(working copy)
@@ -2034,6 +2034,32 @@ not_numeric:
   return FAILURE;
 }
 
+/* F2003, 7.1.7 (3): In init expression, allocatable components
+   must not be data-initialized.  */
+static gfc_try
+check_alloc_comp_init (gfc_expr *e)
+{
+  gfc_component *c;
+  gfc_constructor *ctor;
+
+  gcc_assert (e->expr_type == EXPR_STRUCTURE);
+  gcc_assert (e->ts.type == BT_DERIVED);
+
+  for (c = e->ts.u.derived->components, ctor = e->value.constructor;
+       c; c = c->next, ctor = ctor->next)
+    {
+      if (c->attr.allocatable
+          && ctor->expr->expr_type != EXPR_NULL)
+        {
+	  gfc_error("The data initialization in the derived type constructor "
+		    "at %L for the ALLOCATABLE component '%s' is invalid in "
+		    "initialization expressions", &ctor->expr->where, c->name);
+	  return FAILURE;
+	}
+    }
+
+  return SUCCESS;
+}
 
 static match
 check_init_expr_arguments (gfc_expr *e)
@@ -2383,10 +2409,18 @@ check_init_expr (gfc_expr *e)
       break;
 
     case EXPR_STRUCTURE:
-      if (e->ts.is_iso_c)
-	t = SUCCESS;
-      else
-	t = gfc_check_constructor (e, check_init_expr);
+      t = e->ts.is_iso_c ? SUCCESS : FAILURE;
+      if (t == SUCCESS)
+	break;
+
+      t = check_alloc_comp_init (e);
+      if (t == FAILURE)
+	break;
+
+      t = gfc_check_constructor (e, check_init_expr);
+      if (t == FAILURE)
+	break;
+
       break;
 
     case EXPR_ARRAY:

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