windows: usage of deprecated std:wstring_convert #32361

issue fanquake openend 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:

     0../../src/common/system.cpp: In function 'void runCommand(const std::string&)':
     1../../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]
     2   52 |     int nErr = ::_wsystem(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,wchar_t>().from_bytes(strCommand).c_str());
     3      |                                ^~~~~~~~~~~~~~~
     4In 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,
     5                 from ../../src/util/string.h:13,
     6                 from ../../src/tinyformat.h:149,
     7                 from ../../src/logging.h:10,
     8                 from ../../src/common/system.cpp:10:
     9/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
    10  262 |     class _GLIBCXX17_DEPRECATED wstring_convert
    11      |                                 ^~~~~~~~~~~~~~~
    
  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:

     0  // Converts a Windows wide multi-byte UTF-16 string to a UTF-8 string.
     1  // See http://utf8everywhere.org/#windows
     2  std::string toUtf8(const std::wstring& wstr) {
     3    if (wstr.empty()) return std::string();
     4    int size_needed = WideCharToMultiByte(
     5        CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
     6    std::string strTo(size_needed, 0);
     7    WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0],
     8                        size_needed, NULL, NULL);
     9    return strTo;
    10  }
    11
    12  // Converts a UTF-8 string to a Windows UTF-16 multi-byte wide character
    13  // string.
    14  // See http://utf8everywhere.org/#windows
    15  std::wstring toUtf16(const std::string& str) {
    16    if (str.empty()) return std::wstring();
    17    int size_needed =
    18        MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
    19    std::wstring strTo(size_needed, 0);
    20    MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &strTo[0],
    21                        size_needed);
    22    return strTo;
    23  }
    
  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.


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: 2025-05-05 12:12 UTC

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