http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51434
--- Comment #12 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-12-07 17:20:14 UTC --- (In reply to comment #10) > > Draft patch - one probably needs to do something similar for derived types. > The patch breaks the "Different CHARACTER lengths (%d/%d) in array > constructor" diagnostic, e.g. gfortran.dg/bounds_check_array_ctor_3.f90. Actually, it does not - that was a left over from an earlier attempt (in expr.c's gfc_get_character_expr). The following should work, but is not regtested. I am not sure about the BT_DERIVED part; valid examples seem to work fine while the following invalid code ICEs in decl.c's build_struct. That's independent of the patch. type t character :: z end type t type(t), parameter :: s(5) = t('a') type b character :: y(5) = transfer('aaaaa', s) end type end --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1502,6 +1502,18 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus) array->shape = gfc_get_shape (sym->as->rank); for (n = 0; n < sym->as->rank; n++) spec_dimen_size (sym->as, n, &array->shape[n]); + array->ts.is_c_interop = init->ts.is_c_interop; + if (init->ts.type == BT_CHARACTER) + { + if (init->ts.u.cl->length == NULL) + init->ts.u.cl->length + = gfc_get_int_expr (gfc_default_integer_kind, + &init->where, + init->value.character.length); + array->ts.u.cl = init->ts.u.cl; + } + else if (init->ts.type == BT_DERIVED) + array->ts.u.derived = init->ts.u.derived; init = array; mpz_clear (size);