aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flang-rt/lib/runtime/edit-output.cpp7
-rw-r--r--flang-rt/unittests/Runtime/NumericalFormatTest.cpp4
2 files changed, 9 insertions, 2 deletions
diff --git a/flang-rt/lib/runtime/edit-output.cpp b/flang-rt/lib/runtime/edit-output.cpp
index 3699213..f90b6fb 100644
--- a/flang-rt/lib/runtime/edit-output.cpp
+++ b/flang-rt/lib/runtime/edit-output.cpp
@@ -182,8 +182,11 @@ bool RT_API_ATTRS EditIntegerOutput(IoStatementState &io, const DataEdit &edit,
leadingSpaces = 1;
} else if (!edit.width) {
// Bare 'I' and 'G' are interpreted with various default widths in the
- // compilers that support them, so there's always some leading space.
- leadingSpaces = std::max(1, leadingSpaces);
+ // compilers that support them, so there's always some leading space
+ // after column 1.
+ if (io.GetConnectionState().positionInRecord > 0) {
+ leadingSpaces = 1;
+ }
}
return EmitRepeated(io, ' ', leadingSpaces) &&
EmitAscii(io, n < 0 ? "-" : "+", signChars) &&
diff --git a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
index 36170ea..a752f9d 100644
--- a/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang-rt/unittests/Runtime/NumericalFormatTest.cpp
@@ -842,6 +842,10 @@ TEST(IOApiTests, FormatIntegerValues) {
{"(G0.2)", -1, "-1"},
{"(G0.2)", 999, "999"},
{"(G0.4)", 999, "999"},
+ {"(I)", 999, "999"},
+ {"(G)", 999, "999"},
+ {"('x',I)", 999, "x 999"},
+ {"('x',G)", 999, "x 999"},
};
for (auto const &[fmt, value, expect] : intTestCases) {