https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113223
Bug ID: 113223 Summary: NAMELIST internal write missing leading blank character Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libfortran Assignee: unassigned at gcc dot gnu.org Reporter: kargl at gcc dot gnu.org Target Milestone: --- Found at https://github.com/llvm/llvm-project/issues/76798 Program test_namelist_blank Integer :: i,j Character(300) ::s Namelist /nml1/i,j i = 99 j = 42 Write (s,NML=nml1) Write (*,'("Internal ",A)') Merge('ok ','bug',s(1:1)==' ') Write (*,NML=nml1) End Program test_namelist_blank F2018 13.11.4.3 Namelist output records ... Except for new records created by explicit formatting within a defined output procedure or by continuation of delimited character sequences, each output record begins with a blank character. Patch diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index f94e180ba33..a7cf5d9b233 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -2466,6 +2466,8 @@ namelist_write (st_parameter_dt *dtp) dtp->u.p.nml_delim = '\0'; } + if (is_internal_unit (dtp)) + write_character (dtp, " ", 1, 1, NODELIM); write_character (dtp, "&", 1, 1, NODELIM); /* Write namelist name in upper case - f95 std. */