windows: usage of deprecated `std:wstring_convert` #32361

issue fanquake opened this issue on April 28, 2025
  1. fanquake commented at 9:47 AM on April 28, 2025: member

    std:wstring_convert was deprecated in C++17 & is removed in C++26. Cross-compiling for Windows with GCC 15.1.0 is warning about this:

    ../../src/common/system.cpp: In function 'void runCommand(const std::string&)':
    ../../src/common/system.cpp:52:32: warning: 'template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc> class std::__cxx11::wstring_convert' is deprecated [-Wdeprecated-declarations]
       52 |     int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().from_bytes(strCommand).c_str());
          |                                ^~~~~~~~~~~~~~~
    In file included from /opt/homebrew/Cellar/mingw-w64/12.0.0_3/toolchain-x86_64/x86_64-w64-mingw32/include/c++/15.1.0/locale:47,
                     from ../../src/util/string.h:13,
                     from ../../src/tinyformat.h:149,
                     from ../../src/logging.h:10,
                     from ../../src/common/system.cpp:10:
    /opt/homebrew/Cellar/mingw-w64/12.0.0_3/toolchain-x86_64/x86_64-w64-mingw32/include/c++/15.1.0/bits/locale_conv.h:262:33: note: declared here
      262 |     class _GLIBCXX17_DEPRECATED wstring_convert
          |                                 ^~~~~~~~~~~~~~~
    
  2. hebasto added the label Windows on Apr 28, 2025
  3. laanwj commented at 11:16 AM on April 28, 2025: member

    Apparently there is no direct replacement in the standard library.

    i hope we can replace runCommand with use of the subprocess library soon, to unify the "launch subprocess" path.

  4. fanquake commented at 11:55 AM on April 28, 2025: member

    with use of the subprocess library soon

    Note that subprocess.h is also using wstring_convert: https://github.com/bitcoin/bitcoin/blob/d62c2d82e14d27307d8790fd9d921b740b784668/src/util/subprocess.h#L1071.

  5. laanwj commented at 10:29 AM on April 29, 2025: member

    Note that subprocess.h is also using wstring_convert:

    Ugh. Well at least it's an upstream issue for them, too, then.

  6. laanwj commented at 10:32 AM on April 29, 2025: member

    So in principle modern Windows can use UTF-8 on the 8-bit APIs, removing need for any conversion, but i'm not sure starting from when, and this relies on setting a specific code page globally at startup. Edit: according to Microsoft this is since Windows Version 1903 (May 2019 Update). This requires providing a "Fusion manifest for an unpackaged Win32 app", whatever that means, if we can even do this with mingw32.

    Alternatively we could borrow these (windows specific) functions from our leveldb patch:

      // Converts a Windows wide multi-byte UTF-16 string to a UTF-8 string.
      // See http://utf8everywhere.org/#windows
      std::string toUtf8(const std::wstring& wstr) {
        if (wstr.empty()) return std::string();
        int size_needed = WideCharToMultiByte(
            CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
        std::string strTo(size_needed, 0);
        WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0],
                            size_needed, NULL, NULL);
        return strTo;
      }
    
      // Converts a UTF-8 string to a Windows UTF-16 multi-byte wide character
      // string.
      // See http://utf8everywhere.org/#windows
      std::wstring toUtf16(const std::string& str) {
        if (str.empty()) return std::wstring();
        int size_needed =
            MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
        std::wstring strTo(size_needed, 0);
        MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &strTo[0],
                            size_needed);
        return strTo;
      }
    
  7. hebasto commented at 12:16 PM on April 29, 2025: member

    This requires providing a "Fusion manifest for an unpackaged Win32 app", whatever that means, if we can even do this with mingw32.

    I believe we can use an approach similar to the one described at https://stackoverflow.com/questions/33000158/embed-manifest-file-to-require-administrator-execution-level-with-mingw32.

  8. laanwj commented at 1:39 PM on April 29, 2025: member

    Great, good to know that's possible. i guess by the time we switch to C++26 and this becomes a blocking issue, it will be fine to require a 2019 windows version, and we can simplify things by using the "ASCII" Windows APIs everywhere and provide strings as-is. This would also allow dropping the leveldb patch.

  9. hebasto commented at 4:56 PM on April 29, 2025: member

    Great, good to know that's possible. i guess by the time we switch to C++26 and this becomes a blocking issue, it will be fine to require a 2019 windows version, and we can simplify things by using the "ASCII" Windows APIs everywhere and provide strings as-is. This would also allow dropping the leveldb patch.

    A proof of concept is available in #32380.

  10. achow101 referenced this in commit 68ac9f116c on Apr 30, 2025
  11. hebasto referenced this in commit 3bb30658e6 on Oct 28, 2025
  12. Kino1994 referenced this in commit 4a3b990043 on Jun 28, 2026
  13. Kino1994 referenced this in commit 7408c00121 on Jun 28, 2026
  14. BigcoinBGC referenced this in commit acdd7c0380 on Jun 30, 2026
  15. BigcoinBGC referenced this in commit c6ce75f4dc on Jun 30, 2026
  16. fanquake commented at 2:56 PM on August 7, 2026: member

    Closing after #35704.

  17. fanquake closed this on Aug 7, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-17 03:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me