https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118747
--- Comment #3 from anlauf at gcc dot gnu.org --- The issue in comment#2 is fixed by the following - I'd say obvious - patch: diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index 017f184f179..81fa8756a91 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -8144,7 +8144,7 @@ gfc_generate_function_code (gfc_namespace * ns) : gfc_generate_initializer (&rsym->ts, true); if (init_exp) { - tmp = gfc_trans_structure_assign (result, init_exp, 0); + tmp = gfc_trans_structure_assign (result, init_exp, true); gfc_free_expr (init_exp); gfc_add_expr_to_block (&init, tmp); } This turns the broken initialization of the allocatable, fixed-length character component of the function result into a regular one, also confirmed by valgrind.