This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR libstdc++/59568 fix error handling for std::complex stream extraction


On 14/12/17 11:28 +0000, Jonathan Wakely wrote:
On 13/12/17 18:42 +0000, Jonathan Wakely wrote:
The bug here is that we called putback even if the initial __is >> __ch
extraction failed and set eofbit, and putback clears the eofbit. I
found a number of other problems though, such as not even trying to
call putback after failing to find the ',' and ')' characters.

I decided to rewrite the function following the proposed resolution
for https://wg21.link/lwg2714 which is a much more precise
specification for much more desirable semantics.

	PR libstdc++/59568
	* include/std/complex (operator>>): Implement proposed resolution to
	LWG 2714. Use putback if and only if a character has been successfully
	extracted but isn't a delimiter. Use ctype::widen and traits::eq when
	testing if extracted characters match delimiters.
	* testsuite/26_numerics/complex/dr2714.cc: New test.

Tested powerpc64le-linux, committed to trunk.

Here's a tweak for the testcase. Tested x86_64-linux, committed to trunk.

And an extra test for whitespace handling. Committed to trunk.


commit fdcb019de0eab2e6b3d0844422e8984bf5d95622
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Dec 14 11:41:43 2017 +0000

    Test whitespace handling in std::complex extraction
    
            * testsuite/26_numerics/complex/inserters_extractors/char/dr2714.cc:
            Add tests using noskipws.

diff --git a/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/dr2714.cc b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/dr2714.cc
index 17fb8a249d9..952c52f4a2b 100644
--- a/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/dr2714.cc
+++ b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/dr2714.cc
@@ -145,10 +145,38 @@ test03()
   in.clear();
 }
 
+void
+test04()
+{
+  // Test noskipws handling
+  std::istringstream in;
+  const char* bad_inputs[] = {
+    " 1", " (2)", "( 2)", "(2 )", "(2 ,3)", "(2,3 )", 0
+  };
+  const std::complex<double> c0(-1, -1);
+  std::complex<double> c;
+  for (int i = 0; bad_inputs[i]; ++i)
+  {
+    c = c0;
+    in.clear();
+    in.str(bad_inputs[i]);
+    in >> std::noskipws >> c;
+    VERIFY( in.fail() );
+    VERIFY( c == c0 );
+
+    in.clear();
+    in.str(bad_inputs[i]);
+    in >> std::skipws >> c;
+    VERIFY( !in.fail() );
+    VERIFY( c != c0 );
+  }
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
+  test04();
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]