https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104311
--- Comment #7 from anlauf at gcc dot gnu.org --- (In reply to anlauf from comment #6) > (In reply to anlauf from comment #2) > > We could limit the size of the resulting array constructor, using e.g. > > flag_max_array_constructor. > > Sample patch: Well, thinking some more and rereading the standard text, I see I got it wrong. A comment in gfc_calculate_transfer_sizes explains what it should be. So the right thing is simply: diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index d6c6767ae9e..fc97bb1371e 100644 --- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -6150,7 +6150,7 @@ gfc_calculate_transfer_sizes (gfc_expr *source, gfc_expr *mold, gfc_expr *size, * representation is not shorter than that of SOURCE. * If SIZE is present, the result is an array of rank one and size SIZE. */ - if (result_elt_size == 0 && *source_size > 0 && !size + if (result_elt_size == 0 && *source_size > 0 && (mold->expr_type == EXPR_ARRAY || mold->rank)) { gfc_error ("%<MOLD%> argument of %<TRANSFER%> intrinsic at %L is an "