libstdc++: Implement std::ios_base::noreplace for C++23 [PR59769]
authorJonathan Wakely <jwakely@redhat.com>
Wed, 8 Dec 2021 20:58:11 +0000 (20:58 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 9 Dec 2021 22:59:48 +0000 (22:59 +0000)
commita219139e986a4200a9105d7c1fa63735d2945994
tree1bfb9d1319b884d30ee81a8547539dbcad43db76
parent9e18a25331fa25c3907249fede65a02c6817b06e
libstdc++: Implement std::ios_base::noreplace for C++23 [PR59769]

This implements my P2467R0 proposal to support opening an fstream in
exclusive mode. The new constant is also supported pre-C++23 as
std::ios_base::__noreplace.

This proposal hasn't been approved for C++23 yet, but I am confident it
will be, as this is restoring a feture found in pre-ISO C++ iostreams
implementations (and still present in the MSVC library as _Noreplace).
If the proposal fails for C++23 we can remove the ios::noreplace
name and just keep ios::__noreplace as an extension.

libstdc++-v3/ChangeLog:

PR libstdc++/59769
* config/io/basic_file_stdio.cc (fopen_mode): Add support for
exclusive mode.
* include/bits/ios_base.h (_S_noreplace): Define new enumerator.
(ios_base::__noreplace): Define.
(ios_base::noreplace): Define for C++23.
* include/std/version (__cpp_lib_ios_noreplace): Define.
* testsuite/27_io/basic_ofstream/open/char/noreplace.cc: New test.
* testsuite/27_io/basic_ofstream/open/wchar_t/noreplace.cc: New test.
libstdc++-v3/config/io/basic_file_stdio.cc
libstdc++-v3/include/bits/ios_base.h
libstdc++-v3/include/std/version
libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/noreplace.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ofstream/open/wchar_t/noreplace.cc [new file with mode: 0644]