[flang] Remove typo that affected complex namelist input
A recent patch to real/complex formatted input included what must
have been an editing hiccup: "++ ++p" instead of "++p". This
compiles, and it broke the consumption of the trailing ')' of a
complex value in namelist input by skipping over the character.
Extend existing test to cover this case.
Differential Revision: https://reviews.llvm.org/D114297
GitOrigin-RevId: d02b318af636a887e85741a5fe699fe3852d1199
diff --git a/runtime/edit-input.cpp b/runtime/edit-input.cpp
index a14216d..3251db1 100644
--- a/runtime/edit-input.cpp
+++ b/runtime/edit-input.cpp
@@ -303,15 +303,15 @@
for (; p < limit && (*p == ' ' || *p == '\t'); ++p) {
}
if (edit.descriptor == DataEdit::ListDirectedImaginaryPart) {
- // Need a trailing ')'
+ // Need to consume a trailing ')' and any white space after
if (p >= limit || *p != ')') {
return false;
}
- for (++ ++p; p < limit && (*p == ' ' || *p == '\t'); ++p) {
+ for (++p; p < limit && (*p == ' ' || *p == '\t'); ++p) {
}
}
- if (p < limit) {
- return false; // unconverted characters remain in field
+ if (edit.width && p < str + *edit.width) {
+ return false; // unconverted characters remain in fixed width field
}
// Success on the fast path!
// TODO: raise converted.flags as exceptions?
diff --git a/unittests/Runtime/NumericalFormatTest.cpp b/unittests/Runtime/NumericalFormatTest.cpp
index a1f0a97..a2bd635 100644
--- a/unittests/Runtime/NumericalFormatTest.cpp
+++ b/unittests/Runtime/NumericalFormatTest.cpp
@@ -144,11 +144,11 @@
}
TEST(IOApiTests, ListInputTest) {
- static const char input[]{",1*,(5.,6..)"};
+ static const char input[]{",1*,(5.,6.),(7.0,8.0)"};
auto cookie{IONAME(BeginInternalListInput)(input, sizeof input - 1)};
// Create real values for IO tests
- static constexpr int numRealValues{6};
+ static constexpr int numRealValues{8};
float z[numRealValues];
for (int j{0}; j < numRealValues; ++j) {
z[j] = -(j + 1);
@@ -166,7 +166,7 @@
<< static_cast<int>(status);
// Ensure writing complex values from floats does not result in an error
- static constexpr int bufferSize{33};
+ static constexpr int bufferSize{39};
char output[bufferSize];
output[bufferSize - 1] = '\0';
cookie = IONAME(BeginInternalListOutput)(output, bufferSize - 1);
@@ -182,7 +182,8 @@
<< static_cast<int>(status);
// Verify output buffer against expected value
- static const char expect[bufferSize]{" (-1.,-2.) (-3.,-4.) (5.,6.) "};
+ static const char expect[bufferSize]{
+ " (-1.,-2.) (-3.,-4.) (5.,6.) (7.,8.) "};
ASSERT_EQ(std::strncmp(output, expect, bufferSize), 0)
<< "Failed complex list-directed output, expected '" << expect
<< "', but got '" << output << "'";