diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2021-12-08 20:58:11 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2021-12-09 22:59:48 +0000 |
commit | a219139e986a4200a9105d7c1fa63735d2945994 (patch) | |
tree | 1bfb9d1319b884d30ee81a8547539dbcad43db76 /libstdc++-v3/include | |
parent | 9e18a25331fa25c3907249fede65a02c6817b06e (diff) | |
download | gcc-a219139e986a4200a9105d7c1fa63735d2945994.zip gcc-a219139e986a4200a9105d7c1fa63735d2945994.tar.gz gcc-a219139e986a4200a9105d7c1fa63735d2945994.tar.bz2 |
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.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/ios_base.h | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/std/version | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index d6626d4..5db0552 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -116,6 +116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _S_in = 1L << 3, _S_out = 1L << 4, _S_trunc = 1L << 5, + _S_noreplace = 1L << 6, _S_ios_openmode_end = 1L << 16, _S_ios_openmode_max = __INT_MAX__, _S_ios_openmode_min = ~__INT_MAX__ @@ -466,6 +467,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Truncate an existing stream when opening. Default for @c ofstream. static const openmode trunc = _S_trunc; + static const openmode __noreplace = _S_noreplace; + +#if __cplusplus >= 202100L +#define __cpp_lib_ios_noreplace 202200L + /// Open a file in exclusive mode. + static const openmode noreplace = _S_noreplace; +#endif + // 27.4.2.1.5 Type ios_base::seekdir /** * @brief This is an enumerated type. diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index eb612f5..23890037 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -296,6 +296,7 @@ #define __cpp_lib_adaptor_iterator_pair_constructor 202106L #define __cpp_lib_byteswap 202110L #define __cpp_lib_invoke_r 202106L +#define __cpp_lib_ios_noreplace 202200L #define __cpp_lib_is_scoped_enum 202011L #if __cpp_lib_concepts # define __cpp_lib_monadic_optional 202110L |