Skip to content

Conversation

@jimporter
Copy link
Contributor

@jimporter jimporter commented Sep 20, 2025

I've split this into several commits for fixing the various compilation failures when switching to C++20. The main issues were:

  • std::u8string uses the new char8_t, which is incompatible with char, so I mostly switched over to using std::string/char (semantically, this should mean effectively "a string using who-knows-what encoding, but probably UTF-8"). Longer term, it might make sense to try and use std::filesystem::path as much as possible.
  • fmt's format strings are now type-checked at compile time, which also revealed a few bugs, like format calls missing arguments and some nested calls to format.

@ricab
Copy link
Collaborator

ricab commented Sep 22, 2025

Thanks for this Jim! Not a review, but I know we have a few places with TODOs for when we make the move. Do you think they could be handled as part of the move? Separate PRs would be OK too, especially for any big ones.

Screenshot from 2025-09-22 11-27-29

@jimporter jimporter force-pushed the c++20 branch 7 times, most recently from 76774f0 to e943fc2 Compare September 23, 2025 02:57
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 84.68900% with 96 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.34%. Comparing base (058cc7a) to head (93ce2af).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
src/daemon/daemon.cpp 69.47% 29 Missing ⚠️
src/utils/utils.cpp 5.26% 18 Missing ⚠️
...rc/platform/backends/qemu/qemu_virtual_machine.cpp 62.50% 12 Missing ⚠️
src/platform/update/new_release_monitor.cpp 50.00% 5 Missing ⚠️
src/daemon/default_vm_image_vault.cpp 69.23% 4 Missing ⚠️
src/platform/backends/qemu/qemu_mount_handler.cpp 76.47% 4 Missing ⚠️
src/platform/platform_unix.cpp 33.33% 4 Missing ⚠️
...tform/backends/libvirt/libvirt_virtual_machine.cpp 50.00% 3 Missing ⚠️
src/cert/ssl_cert_provider.cpp 84.61% 2 Missing ⚠️
src/platform/backends/lxd/lxd_vm_image_vault.cpp 81.81% 2 Missing ⚠️
... and 11 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4378      +/-   ##
==========================================
- Coverage   89.35%   89.34%   -0.02%     
==========================================
  Files         260      260              
  Lines       17549    17310     -239     
==========================================
- Hits        15681    15465     -216     
+ Misses       1868     1845      -23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jimporter jimporter force-pushed the c++20 branch 13 times, most recently from 3fe9219 to 6b49987 Compare September 24, 2025 01:08
@ricab
Copy link
Collaborator

ricab commented Sep 24, 2025

Hey Jim, I haven't been able to follow this very closely, but I just wanted to let you know that I am really happy to see it progressing. It will be great to have this 😃

@ricab ricab mentioned this pull request Sep 24, 2025
Copy link
Contributor

@tobe2098 tobe2098 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instructions need a tweak, almost there.

Copy link
Contributor

@tobe2098 tobe2098 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few changes. I will test the Windows build ASAP and see if it works.

@jimporter jimporter force-pushed the c++20 branch 2 times, most recently from 76cf46f to a2b9923 Compare October 7, 2025 19:37
@jimporter jimporter requested a review from tobe2098 October 7, 2025 19:39
Copy link
Contributor

@tobe2098 tobe2098 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, very solid @jimporter. The build is tested in Windows 11 Pro and it works with the Qt mismatch.

@xmkg
Copy link
Member

xmkg commented Oct 9, 2025

I have to report, building with MSVC 2019 does not seem possible with the C++20 upgrade. The compiler fails with an access violation code while compiling ssh and sftp related code. It is possible that this is a sign to move to MSVC 2022 fully.

It's the same here as well. MSVC 2019 (latest from Chocolatey) appears to crash while attempting to compile sftp_utils.cpp (and bunch of other sftp-related files, too):

[29/291] Building CXX object src\ssh\CMakeFiles\sftp_test.dir\sftp_utils.cpp.obj
FAILED: src/ssh/CMakeFiles/sftp_test.dir/sftp_utils.cpp.obj
C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  /nologo /TP -DABSL_CONSUME_DLL -DFMT_HEADER_ONLY=1 -DLIBSSH_STATIC -DMULTIPASS_COMPILER_MSVC -DMULTIPASS_PLATFORM_WINDOWS -DNOMINMAX -DO_BINARY=0 -DPROTOBUF_USE_DLLS -DQT_CORE_LIB -DQT_NETWORK_LIB -DUNICODE -DWIN32 -DWIN32_LEAN_AND_MEAN -DWIN64 -DYAML_CPP_STATIC_DEFINE -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS -D_UNICODE -D_WIN32_WINNT=0xA00 -D_WIN64 -Dsftp_chmod=ut_sftp_chmod -Dsftp_client_message_free=ut_sftp_client_message_free -Dsftp_client_message_get_data=ut_sftp_client_message_get_data -Dsftp_client_message_get_filename=ut_sftp_client_message_get_filename -Dsftp_close=ut_sftp_close -Dsftp_dir_eof=ut_sftp_dir_eof -Dsftp_free=ut_sftp_free -Dsftp_get_client_message=ut_sftp_get_client_message -Dsftp_get_error=ut_sftp_get_error -Dsftp_handle=ut_sftp_handle -Dsftp_handle_alloc=ut_sftp_handle_alloc -Dsftp_handle_remove=ut_sftp_handle_remove -Dsftp_init=ut_sftp_init -Dsftp_lstat=ut_sftp_lstat -Dsftp_mkdir=ut_sftp_mkdir -Dsftp_new=ut_sftp_new -Dsftp_open=ut_sftp_open -Dsftp_opendir=ut_sftp_opendir -Dsftp_read=ut_sftp_read -Dsftp_readdir=ut_sftp_readdir -Dsftp_readlink=ut_sftp_readlink -Dsftp_reply_attr=ut_sftp_reply_attr -Dsftp_reply_data=ut_sftp_reply_data -Dsftp_reply_handle=ut_sftp_reply_handle -Dsftp_reply_name=ut_sftp_reply_name -Dsftp_reply_names=ut_sftp_reply_names -Dsftp_reply_names_add=ut_sftp_reply_names_add -Dsftp_reply_status=ut_sftp_reply_status -Dsftp_server_init=ut_sftp_server_init -Dsftp_server_new=ut_sftp_server_new -Dsftp_setstat=ut_sftp_setstat -Dsftp_stat=ut_sftp_stat -Dsftp_symlink=ut_sftp_symlink -Dsftp_unlink=ut_sftp_unlink -Dsftp_write=ut_sftp_write -Dssh_add_channel_callbacks=ut_ssh_add_channel_callbacks -Dssh_channel_change_pty_size=ut_ssh_channel_change_pty_size -Dssh_channel_get_exit_status=ut_ssh_channel_get_exit_status -Dssh_channel_is_closed=ut_ssh_channel_is_closed -Dssh_channel_is_eof=ut_ssh_channel_is_eof -Dssh_channel_is_open=ut_ssh_channel_is_open -Dssh_channel_new=ut_ssh_channel_new -Dssh_channel_open_session=ut_ssh_channel_open_session -Dssh_channel_read_timeout=ut_ssh_channel_read_timeout -Dssh_channel_request_exec=ut_ssh_channel_request_exec -Dssh_channel_request_pty=ut_ssh_channel_request_pty -Dssh_channel_request_shell=ut_ssh_channel_request_shell -Dssh_connect=ut_ssh_connect -Dssh_event_dopoll=ut_ssh_event_dopoll -Dssh_get_error=ut_ssh_get_error -Dssh_is_connected=ut_ssh_is_connected -Dssh_new=ut_ssh_new -Dssh_options_set=ut_ssh_options_set -Dssh_userauth_publickey=ut_ssh_userauth_publickey -IC:\workspace\multipass\include -IC:\workspace\multipass\build\gen -IC:\workspace\multipass\3rd-party\libssh\libssh\include -IC:\workspace\multipass\build\3rd-party\libssh\libssh -IC:\workspace\multipass\build\3rd-party\libssh\libssh\include -I\include -IC:\workspace\multipass\3rd-party\yaml-cpp\include -IC:\workspace\multipass\3rd-party\xz-decoder\xz-embedded\linux\include\linux -external:IC:\workspace\multipass\build\vcpkg_installed\x64-windows\include -external:I"C:\Program Files\OpenSSL-Win64\include" -external:IC:\workspace\6.5.2\msvc2019_64\include\QtCore -external:IC:\workspace\6.5.2\msvc2019_64\include -external:IC:\workspace\6.5.2\msvc2019_64\mkspecs\win32-msvc -external:IC:\workspace\6.5.2\msvc2019_64\include\QtNetwork -external:W0 /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++20 -MDd /utf-8 -Zc:__cplusplus -permissive- -utf-8 /showIncludes /Fosrc\ssh\CMakeFiles\sftp_test.dir\sftp_utils.cpp.obj /Fdsrc\ssh\CMakeFiles\sftp_test.dir\sftp_test.pdb /FS -c C:\workspace\multipass\src\ssh\sftp_utils.cpp
C:\workspace\multipass\build\vcpkg_installed\x64-windows\include\google/protobuf/message_lite.h(1191): warning C4141: 'inline': used more than once
C:\workspace\multipass\build\vcpkg_installed\x64-windows\include\google/protobuf/message_lite.h(1297): warning C4141: 'inline': used more than once
C:\workspace\multipass\src\ssh\sftp_utils.cpp(66) : fatal error C1001: Internal compiler error.
(compiler file 'D:\a\_work\1\s\src\vctools\Compiler\Utc\src\p2\main.c', line 213)
 To work around this problem, try simplifying or changing the program near the locations listed above.       
If possible please provide a repro here: https://developercommunity.visualstudio.com
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information

It seems like it's going to be a hard requirement to switch to VS2022. I don't see any downsides to that since VS2026 is also just around the corner; it's a good time to upgrade.

Copy link
Member

@xmkg xmkg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, also ran the cli-tests on Win11 Pro, no issues.

Thanks for the initiative, @jimporter! This will enable us to modernize the codebase further.

The coverage regressions are all due to already uncovered code being touched by refactoring.

@xmkg xmkg self-requested a review October 9, 2025 13:33
Copy link
Member

@xmkg xmkg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checked the coverage regressions to confirm that they were already uncovered before.

@xmkg xmkg added this pull request to the merge queue Oct 9, 2025
@jimporter
Copy link
Contributor Author

C:\workspace\multipass\src\ssh\sftp_utils.cpp(66) : fatal error C1001: Internal compiler error.

Wow, haven't seen an ICE from MSVC in a while. That takes me back! Glad to see it's all working under MSVC 2022 though.

Merged via the queue into main with commit 5bb0355 Oct 9, 2025
20 of 22 checks passed
@xmkg xmkg deleted the c++20 branch October 9, 2025 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants