From: Janus Weil Date: Mon, 29 Dec 2014 10:45:21 +0000 (+0100) Subject: re PR fortran/60357 ([F08] structure constructor with unspecified values for allocata... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7430df9766d0706da1dc969d7aae9a6c9ed367d8;p=gcc.git re PR fortran/60357 ([F08] structure constructor with unspecified values for allocatable components) 2014-12-29 Janus Weil PR fortran/60357 * array.c (check_constructor): Ignore empty expressions. * expr.c (check_alloc_comp_init): Check if constructor expression exists. * primary.c (build_actual_constructor): Warn for absent alloc-comp initializers in pre-2008 standards. 2014-12-29 Janus Weil PR fortran/60357 * gfortran.dg/alloc_comp_constructor_7.f90: New. From-SVN: r219098 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d7a76a3c9f9..3329c42347d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2014-12-29 Janus Weil + + PR fortran/60357 + * array.c (check_constructor): Ignore empty expressions. + * expr.c (check_alloc_comp_init): Check if constructor expression + exists. + * primary.c (build_actual_constructor): Warn for absent alloc-comp + initializers in pre-2008 standards. + 2014-12-28 Thomas Koenig PR fortran/56867 diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index e60b938a174..67bd42b511f 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -1309,6 +1309,9 @@ check_constructor (gfc_constructor_base ctor, bool (*check_function) (gfc_expr * { e = c->expr; + if (!e) + continue; + if (e->expr_type != EXPR_ARRAY) { if (!(*check_function)(e)) diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index a887d4c5661..51f527dad12 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2201,7 +2201,7 @@ check_alloc_comp_init (gfc_expr *e) ctor = gfc_constructor_first (e->value.constructor); comp; comp = comp->next, ctor = gfc_constructor_next (ctor)) { - if (comp->attr.allocatable + if (comp->attr.allocatable && ctor->expr && ctor->expr->expr_type != EXPR_NULL) { gfc_error ("Invalid initialization expression for ALLOCATABLE " diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 77522e54bf0..78c24d48015 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2367,6 +2367,13 @@ build_actual_constructor (gfc_structure_ctor_component **comp_head, return false; value = gfc_copy_expr (comp->initializer); } + else if (comp->attr.allocatable) + { + if (!gfc_notify_std (GFC_STD_F2008, "No initializer for " + "allocatable component '%s' given in the structure " + "constructor at %C", comp->name)) + return false; + } else if (!comp->attr.deferred_parameter) { gfc_error ("No initializer for component %qs given in the" diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c5ea71d342..5706f62f922 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-12-29 Janus Weil + + PR fortran/60357 + * gfortran.dg/alloc_comp_constructor_7.f90: New. + 2014-12-29 Hans-Peter Nilsson * gcc.dg/lto/pr59626_0.c (ASMNAME, ASMNAME2, STRING): Define. diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_constructor_7.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_constructor_7.f90 new file mode 100644 index 00000000000..45d82726ae0 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/alloc_comp_constructor_7.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! +! PR 60357: [F08] structure constructor with unspecified values for allocatable components +! +! Contributed by Antony Lewis + +Type A + integer :: X = 1 + integer, allocatable :: y + integer, allocatable :: z(:) +end type + +Type(A) :: Me = A(X=1) + +if (allocated(Me%y)) call abort +if (allocated(Me%z)) call abort + +end