[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-09-13 Thread aldyh at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #13 from Aldy Hernandez  ---
Author: aldyh
Date: Wed Sep 13 16:43:11 2017
New Revision: 252358

URL: https://gcc.gnu.org/viewcvs?rev=252358=gcc=rev
Log:
PR libstdc++/81751 don't call fflush(NULL)

PR libstdc++/79820
PR libstdc++/81751
* config/io/basic_file_stdio.cc (sys_open(FILE*, ios_base::openmode)):
Call fflush on the stream instead of calling sync() while _M_cfile is
null. Restore original value of errno.
* testsuite/ext/stdio_filebuf/char/79820.cc: New.
* testsuite/ext/stdio_filebuf/char/81751.cc: New.

Added:
branches/range-gen2/libstdc++-v3/testsuite/ext/stdio_filebuf/char/79820.cc
branches/range-gen2/libstdc++-v3/testsuite/ext/stdio_filebuf/char/81751.cc
Modified:
branches/range-gen2/libstdc++-v3/ChangeLog
branches/range-gen2/libstdc++-v3/config/io/basic_file_stdio.cc

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-09-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

Jonathan Wakely  changed:

   What|Removed |Added

   Target Milestone|8.0 |5.5

--- Comment #12 from Jonathan Wakely  ---
Fixed for 5.5, 6.5 and 7,.3

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-09-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #11 from Jonathan Wakely  ---
Author: redi
Date: Mon Sep  4 17:09:05 2017
New Revision: 251680

URL: https://gcc.gnu.org/viewcvs?rev=251680=gcc=rev
Log:
PR libstdc++/81751 don't call fflush(NULL)

Backport from mainline
2017-08-09  Jonathan Wakely  

PR libstdc++/79820
PR libstdc++/81751
* config/io/basic_file_stdio.cc (sys_open(FILE*, ios_base::openmode)):
Call fflush on the stream instead of calling sync() while _M_cfile is
null. Restore original value of errno.
* testsuite/ext/stdio_filebuf/char/79820.cc: New.
* testsuite/ext/stdio_filebuf/char/81751.cc: New.

Added:
   
branches/gcc-5-branch/libstdc++-v3/testsuite/ext/stdio_filebuf/char/79820.cc
   
branches/gcc-5-branch/libstdc++-v3/testsuite/ext/stdio_filebuf/char/81751.cc
Modified:
branches/gcc-5-branch/libstdc++-v3/ChangeLog
branches/gcc-5-branch/libstdc++-v3/config/io/basic_file_stdio.cc

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-09-04 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #10 from Jonathan Wakely  ---
Author: redi
Date: Mon Sep  4 16:52:30 2017
New Revision: 251676

URL: https://gcc.gnu.org/viewcvs?rev=251676=gcc=rev
Log:
PR libstdc++/81751 don't call fflush(NULL)

Backport from mainline
2017-08-09  Jonathan Wakely  

PR libstdc++/79820
PR libstdc++/81751
* config/io/basic_file_stdio.cc (sys_open(FILE*, ios_base::openmode)):
Call fflush on the stream instead of calling sync() while _M_cfile is
null. Restore original value of errno.
* testsuite/ext/stdio_filebuf/char/79820.cc: New.
* testsuite/ext/stdio_filebuf/char/81751.cc: New.

Added:
   
branches/gcc-6-branch/libstdc++-v3/testsuite/ext/stdio_filebuf/char/79820.cc
   
branches/gcc-6-branch/libstdc++-v3/testsuite/ext/stdio_filebuf/char/81751.cc
Modified:
branches/gcc-6-branch/libstdc++-v3/ChangeLog
branches/gcc-6-branch/libstdc++-v3/config/io/basic_file_stdio.cc

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-14 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #12 from Jonathan Wakely  ---
I was wrong, and that code path is used by std::sync_with_stdio(false) when we
reset cin, cout, cerr and clog to use stdio_filebuf stream buffers. So there's
no need for a testcase.

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-14 Thread m-ou...@m-ou.se
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #11 from Maurice Bos  ---
(In reply to Jonathan Wakely from comment #7)
> The bug title says std::ifstream sets errno to zero, but it should never run
> stdio_filebuf::sys_open. Do you have a testcase for this?
> 
> We should still fix it even if it only affects a non-standard extension, but
> it's probably not worth backporting if it doesn't affect std::ifstream.

I encountered it while using the Catch test framework. Found it with a
watchpoint with gdb. Didn't fully inspect the backtrace. It might use some
non-standard extensions. I'll check!

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-14 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

Jonathan Wakely  changed:

   What|Removed |Added

  Known to work||7.2.1, 8.0
   Target Milestone|8.0 |7.3
  Known to fail||5.4.0, 6.4.0, 7.2.0

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-14 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #10 from Jonathan Wakely  ---
Author: redi
Date: Mon Aug 14 12:14:09 2017
New Revision: 251090

URL: https://gcc.gnu.org/viewcvs?rev=251090=gcc=rev
Log:
PR libstdc++/81751 don't call fflush(NULL)

Backport from mainline
2017-08-09  Jonathan Wakely  

PR libstdc++/79820
PR libstdc++/81751
* config/io/basic_file_stdio.cc (sys_open(FILE*, ios_base::openmode)):
Call fflush on the stream instead of calling sync() while _M_cfile is
null. Restore original value of errno.
* testsuite/ext/stdio_filebuf/char/79820.cc: New.
* testsuite/ext/stdio_filebuf/char/81751.cc: New.

Added:
   
branches/gcc-7-branch/libstdc++-v3/testsuite/ext/stdio_filebuf/char/79820.cc
   
branches/gcc-7-branch/libstdc++-v3/testsuite/ext/stdio_filebuf/char/81751.cc
Modified:
branches/gcc-7-branch/libstdc++-v3/ChangeLog
branches/gcc-7-branch/libstdc++-v3/config/io/basic_file_stdio.cc

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-09 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

Jonathan Wakely  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |8.0

--- Comment #9 from Jonathan Wakely  ---
Fixed for GCC 8.

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-09 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #8 from Jonathan Wakely  ---
Author: redi
Date: Wed Aug  9 17:52:10 2017
New Revision: 250993

URL: https://gcc.gnu.org/viewcvs?rev=250993=gcc=rev
Log:
PR libstdc++/81751 don't call fflush(NULL)

PR libstdc++/79820
PR libstdc++/81751
* config/io/basic_file_stdio.cc (sys_open(FILE*, ios_base::openmode)):
Call fflush on the stream instead of calling sync() while _M_cfile is
null. Restore original value of errno.
* testsuite/ext/stdio_filebuf/char/79820.cc: New.
* testsuite/ext/stdio_filebuf/char/81751.cc: New.

Added:
trunk/libstdc++-v3/testsuite/ext/stdio_filebuf/char/79820.cc
trunk/libstdc++-v3/testsuite/ext/stdio_filebuf/char/81751.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/config/io/basic_file_stdio.cc

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-08-08 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #7 from Jonathan Wakely  ---
The bug title says std::ifstream sets errno to zero, but it should never run
stdio_filebuf::sys_open. Do you have a testcase for this?

We should still fix it even if it only affects a non-standard extension, but
it's probably not worth backporting if it doesn't affect std::ifstream.

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-03-14 Thread i.nixman at autistici dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #6 from niXman  ---
Created attachment 40970
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40970=edit
patch

done.

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-03-14 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #5 from Jonathan Wakely  ---
Sorry, I was looking at gcc-6-branch which sets errno=0 in close(), but I
removed that on trunk for PR 65411.

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-03-13 Thread i.nixman at autistici dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #4 from niXman  ---
(In reply to Jonathan Wakely from comment #3)

> and it also needs to be done on line 275.

why?
line 275:
https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/config/io/basic_file_stdio.cc?view=markup#l275

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-03-13 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #3 from Jonathan Wakely  ---
Comment on attachment 40966
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40966
patch

It's quite possible that "errno" is a macro for something called "__errno" on
some systems, so this would fail to compile. I suggest something like
__save_errno instead, and it also needs to be done on line 275.

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-03-13 Thread i.nixman at autistici dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

--- Comment #2 from niXman  ---
Created attachment 40966
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40966=edit
patch

[Bug libstdc++/79820] std::ifstream sets errno to zero

2017-03-02 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79820

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-03-02
 Ever confirmed|0   |1

--- Comment #1 from Jonathan Wakely  ---
I think we should capture the previous value of errno and restore it. I thought
I checked for all places this was needed but maybe I only looked in the include
and src sub-directories, not the config one.