PR libstdc++/53984 handle exceptions in basic_istream::sentry

Submitted by Jonathan Wakely on Aug. 11, 2017, 12:14 a.m.

Details

Message ID 20170811001443.GT15340@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Aug. 11, 2017, 12:14 a.m.
On 26/07/17 23:06 +0100, Jonathan Wakely wrote:
>On 26/07/17 20:14 +0200, Paolo Carlini wrote:
>>Hi again,
>>
>>On 26/07/2017 16:27, Paolo Carlini wrote:
>>>Hi,
>>>
>>>On 26/07/2017 16:21, Andreas Schwab wrote:
>>>>ERROR: 27_io/basic_fstream/53984.cc: unknown dg option: 
>>>>dg-require-file-io 18 {} for " dg-require-file-io 18 "" "
>>>Should be already fixed, a trivial typo.
>>... but now the new test simply fails for me. If I don't spot 
>>something else trivial over the next few hours I guess better 
>>waiting for Jon to look into that.
>
>Sorry about that, I must have only checked for FAILs and missed the
>ERRORs.
>
>It should have been an ifstream not fstream, otherwise the filebuf
>can't even open the file. Fixed like so, committed to trunk.

This FAILs on AIX, because reading from a directory with fread doesn't
fail on AIX. This makes the test check whether reading fails, before
trying to check the behaviour of formatted input functions that fail.

Tested powerpc64le-linux and powerpc-aix, committed to trunk.

Patch hide | download patch | download mbox

commit bb7f3e33c3442f2d93134555bb74cf3ea2991710
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 10 22:02:17 2017 +0100

    PR libstdc++/81808 skip test if reading directory doesn't fail
    
    	PR libstdc++/81808
    	* testsuite/27_io/basic_fstream/53984.cc: Adjust test for targets
    	that allow opening a directory as a FILE and reading from it.

diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc
index e49d2b1..a319aff 100644
--- a/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_fstream/53984.cc
@@ -17,6 +17,8 @@ 
 
 // { dg-require-fileio "" }
 
+// PR libstdc++/53984
+
 #include <fstream>
 #include <testsuite_hooks.h>
 
@@ -26,9 +28,32 @@  test01()
   std::ifstream in(".");
   if (in)
   {
+    char c;
+    if (in.get(c))
+    {
+      // Reading a directory doesn't produce an error on this target
+      // so the formatted input functions below wouldn't fail anyway
+      // (see PR libstdc++/81808).
+      return;
+    }
     int x;
+    in.clear();
+    // Formatted input function should set badbit, but not throw:
     in >> x;
     VERIFY( in.bad() );
+
+    in.clear();
+    in.exceptions(std::ios::badbit);
+    try
+    {
+      // Formatted input function should set badbit, and throw:
+      in >> x;
+      VERIFY( false );
+    }
+    catch (const std::exception&)
+    {
+      VERIFY( in.bad() );
+    }
   }
 }