aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorDaniel Franke <franke.daniel@gmail.com>2009-12-10 14:57:16 -0500
committerDaniel Franke <dfranke@gcc.gnu.org>2009-12-10 14:57:16 -0500
commit604df1167c464da3710e28270e6561d427df0444 (patch)
tree6a1a7279f72c67acf7c1ac2ad4c4844e6d36a1e3 /gcc/fortran
parentdf4d18ad801420200b2698b7d637f4e7d6ba2507 (diff)
downloadgcc-604df1167c464da3710e28270e6561d427df0444.zip
gcc-604df1167c464da3710e28270e6561d427df0444.tar.gz
gcc-604df1167c464da3710e28270e6561d427df0444.tar.bz2
re PR fortran/34402 (Diagnose illegal initialization of derived type containing allocatable component)
gcc/fortran/: 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. gcc/testsuite/: 2009-12-10 Daniel Franke <franke.daniel@gmail.com> PR fortran/34402 * gfortran.dg/alloc_comp_init_expr.f03: New. From-SVN: r155138
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/expr.c42
2 files changed, 45 insertions, 4 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 2eaf6d0..7280dd7 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+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
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index c693773..f0cfd18 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -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("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)
@@ -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: