Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions flang-rt/lib/runtime/edit-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
4 changes: 4 additions & 0 deletions flang-rt/unittests/Runtime/NumericalFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading