https://gcc.gnu.org/g:7761e534ffd1d0194c180e5e3ad7630d38336d9a
commit r15-11383-g7761e534ffd1d0194c180e5e3ad7630d38336d9a Author: Jonathan Wakely <[email protected]> Date: Mon Jul 13 17:57:50 2026 +0100 libstdc++: Fix std module to work with --disable-wchar_t [PR126111] We should not try to export names which are not declared if GCC is configured with --disable-wchar_t. We should also not define the wide stream aliases in <syncstream> and <spanstream>. libstdc++-v3/ChangeLog: PR libstdc++/126111 * include/std/format (__format::__write_escape_seq): Remove unnecessary alias declaration. * include/std/spanstream (wspanbuf, wispanstream, wospanstream) (wspanstream): Only declare for _GLIBCXX_USE_WCHAR_T. * include/std/syncstream (wsyncbuf wosyncstream): Likewise. * src/c++23/std.cc.in: Add preprocessor checks for _GLIBCXX_USE_WCHAR_T to names which depend on it. Reviewed-by: Tomasz KamiĆski <[email protected]> (cherry picked from commit fb0c03ee7afca608cba0419629184b8f442085e2) Diff: --- libstdc++-v3/include/std/format | 5 ++--- libstdc++-v3/include/std/spanstream | 8 +++++++ libstdc++-v3/include/std/syncstream | 5 +++-- libstdc++-v3/src/c++23/std.cc.in | 44 +++++++++++++++++++++++++++++++------ 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index 6c9f2743f6b4..68ad367bda5d 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -1011,7 +1011,6 @@ namespace __format __write_escape_seq(_Out __out, uint_least32_t __val, basic_string_view<_CharT> __prefix) { - using _Str_view = basic_string_view<_CharT>; constexpr size_t __max = 8; char __buf[__max]; const string_view __narrow( @@ -1026,10 +1025,10 @@ namespace __format #ifdef _GLIBCXX_USE_WCHAR_T else { - _CharT __wbuf[__max]; + wchar_t __wbuf[__max]; const size_t __n = __narrow.size(); std::__to_wstring_numeric(__narrow.data(), __n, __wbuf); - __out = __format::__write(__out, _Str_view(__wbuf, __n)); + __out = __format::__write(__out, wstring_view(__wbuf, __n)); } #endif *__out = _Separators<_CharT>::_S_braces()[1]; diff --git a/libstdc++-v3/include/std/spanstream b/libstdc++-v3/include/std/spanstream index 23a340a746e8..7c2ef315e297 100644 --- a/libstdc++-v3/include/std/spanstream +++ b/libstdc++-v3/include/std/spanstream @@ -224,7 +224,9 @@ template<typename _CharT, typename _Traits> { __x.swap(__y); } using spanbuf = basic_spanbuf<char>; +#ifdef _GLIBCXX_USE_WCHAR_T using wspanbuf = basic_spanbuf<wchar_t>; +#endif template<typename _CharT, typename _Traits> class basic_ispanstream @@ -318,7 +320,9 @@ template<typename _CharT, typename _Traits> { __x.swap(__y); } using ispanstream = basic_ispanstream<char>; +#ifdef _GLIBCXX_USE_WCHAR_T using wispanstream = basic_ispanstream<wchar_t>; +#endif template<typename _CharT, typename _Traits> class basic_ospanstream @@ -388,7 +392,9 @@ template<typename _CharT, typename _Traits> { __x.swap(__y); } using ospanstream = basic_ospanstream<char>; +#ifdef _GLIBCXX_USE_WCHAR_T using wospanstream = basic_ospanstream<wchar_t>; +#endif template<typename _CharT, typename _Traits> class basic_spanstream @@ -458,7 +464,9 @@ template<typename _CharT, typename _Traits> { __x.swap(__y); } using spanstream = basic_spanstream<char>; +#ifdef _GLIBCXX_USE_WCHAR_T using wspanstream = basic_spanstream<wchar_t>; +#endif _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/std/syncstream b/libstdc++-v3/include/std/syncstream index e2b5a199ec93..6dfb1367953d 100644 --- a/libstdc++-v3/include/std/syncstream +++ b/libstdc++-v3/include/std/syncstream @@ -309,10 +309,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __x.swap(__y); } using syncbuf = basic_syncbuf<char>; - using wsyncbuf = basic_syncbuf<wchar_t>; - using osyncstream = basic_osyncstream<char>; +#ifdef _GLIBCXX_USE_WCHAR_T + using wsyncbuf = basic_syncbuf<wchar_t>; using wosyncstream = basic_osyncstream<wchar_t>; +#endif _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // __cpp_lib_syncbuf diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/std.cc.in index 36e4361e2a3f..fe92986d79f5 100644 --- a/libstdc++-v3/src/c++23/std.cc.in +++ b/libstdc++-v3/src/c++23/std.cc.in @@ -1329,17 +1329,19 @@ export namespace std #endif using std::formatter; using std::make_format_args; - using std::make_wformat_args; #if __cpp_lib_format >= 202311L // >= C++26 using std::runtime_format; #endif using std::vformat; using std::vformat_to; using std::visit_format_arg; +#ifdef _GLIBCXX_USE_WCHAR_T + using std::make_wformat_args; using std::wformat_args; using std::wformat_context; using std::wformat_parse_context; using std::wformat_string; +#endif #ifdef __cpp_lib_format_ranges using std::format_kind; using std::range_format; @@ -1374,10 +1376,12 @@ export namespace std using std::ifstream; using std::ofstream; using std::swap; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wfilebuf; using std::wfstream; using std::wifstream; using std::wofstream; +#endif } // <functional> @@ -1564,7 +1568,9 @@ export namespace std using std::streamsize; using std::unitbuf; using std::uppercase; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wios; +#endif } // <iosfwd> @@ -1583,9 +1589,11 @@ export namespace std using std::basic_syncbuf; using std::osyncstream; using std::syncbuf; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wosyncstream; using std::wsyncbuf; #endif +#endif } // <iostream> @@ -1595,10 +1603,12 @@ export namespace std using std::cin; using std::clog; using std::cout; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wcerr; using std::wcin; using std::wclog; using std::wcout; +#endif } // <istream> @@ -1608,8 +1618,10 @@ export namespace std using std::basic_istream; using std::iostream; using std::istream; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wiostream; using std::wistream; +#endif using std::ws; using std::operator>>; } @@ -2116,7 +2128,9 @@ export namespace std using std::ends; using std::flush; using std::ostream; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wostream; +#endif using std::operator<<; #ifdef __cpp_lib_syncbuf using std::emit_on_flush; @@ -2537,9 +2551,11 @@ export namespace std using std::ssub_match; using std::sub_match; using std::swap; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wcsub_match; using std::wregex; using std::wssub_match; +#endif using std::operator==; using std::operator<=>; using std::operator<<; @@ -2555,20 +2571,24 @@ export namespace std using std::smatch; using std::sregex_iterator; using std::sregex_token_iterator; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wcmatch; using std::wcregex_iterator; using std::wcregex_token_iterator; using std::wsmatch; using std::wsregex_iterator; using std::wsregex_token_iterator; +#endif namespace pmr { #if _GLIBCXX_USE_CXX11_ABI using std::pmr::cmatch; using std::pmr::match_results; using std::pmr::smatch; +#ifdef _GLIBCXX_USE_WCHAR_T using std::pmr::wcmatch; using std::pmr::wsmatch; +#endif #endif } } @@ -2637,17 +2657,19 @@ export namespace std export namespace std { using std::basic_spanbuf; - using std::spanbuf; - using std::wspanbuf; using std::basic_ispanstream; - using std::ispanstream; - using std::wispanstream; using std::basic_ospanstream; - using std::ospanstream; - using std::wospanstream; using std::basic_spanstream; + using std::spanbuf; + using std::ispanstream; + using std::ospanstream; using std::spanstream; +#ifdef _GLIBCXX_USE_WCHAR_T + using std::wspanbuf; + using std::wispanstream; + using std::wospanstream; using std::wspanstream; +#endif } #endif @@ -2663,10 +2685,12 @@ export namespace std using std::stringbuf; using std::stringstream; using std::swap; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wistringstream; using std::wostringstream; using std::wstringbuf; using std::wstringstream; +#endif } // <stack> @@ -2761,7 +2785,9 @@ export namespace std { using std::basic_streambuf; using std::streambuf; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wstreambuf; +#endif } // <string> @@ -2788,7 +2814,9 @@ export namespace std using std::stoull; using std::string; using std::to_string; +#ifdef _GLIBCXX_USE_WCHAR_T using std::to_wstring; +#endif using std::u16string; using std::u32string; using std::u8string; @@ -2853,9 +2881,11 @@ export namespace std using std::basic_osyncstream; using std::osyncstream; using std::syncbuf; +#ifdef _GLIBCXX_USE_WCHAR_T using std::wosyncstream; using std::wsyncbuf; #endif +#endif } // 19.5 <system_error>
