+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.
+
2008-12-08 Daniel Kraft <d@domob.eu>
PR fortran/41177
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("Invalid initialization expression for ALLOCATABLE "
+ "component '%s' in structure constructor at %L",
+ c->name, &ctor->expr->where);
+ return FAILURE;
+ }
+ }
+
+ return SUCCESS;
+}
static match
check_init_expr_arguments (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:
+2009-12-10 Daniel Franke <franke.daniel@gmail.com>
+
+ PR fortran/34402
+ * gfortran.dg/alloc_comp_init_expr.f03: New.
+
2009-12-09 David Edelsohn <edelsohn@gnu.org>
* gcc.target/powerpc/bswap64-4.c: Disable on AIX.
--- /dev/null
+! { dg-do "compile" }
+! PR fortran/34402 - allocatable components shall not be
+! data-initialized in init expr
+
+ type t
+ real, allocatable :: x(:)
+ end type
+
+ ! The following is illegal!
+ type (t) :: bad = t ( (/ 1., 3., 5., 7., 9. /) ) ! { dg-error "Invalid initialization expression" }
+
+ ! This is ok
+ type (t) :: ok = t ( NULL() )
+end