diff --git a/gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f b/gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f index b5205a8bf53..89a8df2caff 100644 --- a/gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f +++ b/gcc/testsuite/gfortran.dg/g77/f77-edit-s-out.f @@ -16,5 +16,5 @@ C ( dg-output "^" } write(*,40) 0 ! { dg-output " \\+0(\n|\r\n|\r)" } C 15.5.9 - Note 5: When SP editing is in effect, the plus sign is not optional write(*,50) 11 ! { dg-output "\\*\\*(\n|\r\n|\r)" } -C { dg-output "\$" {xfail *-*-*} } gfortran PR 16434 +C { dg-output "\$" } end diff --git a/libgfortran/io/format.c b/libgfortran/io/format.c index 23b8d5ebf1b..0e42810873e 100644 --- a/libgfortran/io/format.c +++ b/libgfortran/io/format.c @@ -552,6 +552,7 @@ format_item: case FMT_BN: case FMT_BZ: get_fnode (&head, &tail, t); + tail->repeat = 1; goto between_desc; case FMT_COLON: diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 4e22b703ea8..f98ec1f1f36 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -425,9 +425,12 @@ output_float (fnode *f, double value, int len) } /* Round the value. */ - if (nbefore + nafter < ndigits && nbefore + nafter > 0) + if (nbefore + nafter == 0) + ndigits = 0; + else if (nbefore + nafter < ndigits) { - i = nbefore + nafter; + ndigits = nbefore + nafter; + i = ndigits; if (digits[i] >= '5') { /* Propagate the carry. */ @@ -513,6 +516,16 @@ output_float (fnode *f, double value, int len) if (out == NULL) return; + /* Zero values always output as positive, even if the value was negative + before rounding. */ + for (i = 0; i < ndigits; i++) + { + if (digits[i] != '0') + break; + } + if (i == ndigits) + sign = calculate_sign (0); + /* Work out how much padding is needed. */ nblanks = w - (nbefore + nzero + nafter + edigits + 1); if (sign != SIGN_NONE)