Skip to content

Fix std::format type mismatch mixing std::wstring and std::string#40199

Closed
benhillis wants to merge 1 commit intofeature/wsl-for-appsfrom
fix/wstring-format-mismatch
Closed

Fix std::format type mismatch mixing std::wstring and std::string#40199
benhillis wants to merge 1 commit intofeature/wsl-for-appsfrom
fix/wstring-format-mismatch

Conversation

@benhillis
Copy link
Copy Markdown
Member

Problem

In WSLCContainer::Create(), the bind source path for file mounts is constructed using std::format with a narrow format string but passing sourceFilename (std::wstring) alongside parentVMPath (std::string).

std::format with a narrow format string does not accept std::wstring arguments in standard C++20. This is a type mismatch that could cause compilation failures or undefined behavior.

Fix

Convert sourceFilename from std::wstring to std::string via WideToMultiByte() before passing it to std::format, consistent with how the codebase handles wide-to-narrow conversions elsewhere.

Testing

Type-correctness fix in the volume bind path construction for file mounts (introduced in #40137).

In WSLCContainer::Create, the bind source path for file mounts was
constructed using std::format with a narrow format string but passing
sourceFilename (std::wstring) alongside parentVMPath (std::string).
This is a type mismatch in standard C++20 std::format.

Convert sourceFilename to narrow string via WideToMultiByte before
formatting to ensure type consistency and correct behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 17:53
@benhillis benhillis closed this Apr 16, 2026
@benhillis benhillis deleted the fix/wstring-format-mismatch branch April 16, 2026 17:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a C++20 std::format argument type mismatch in the WSLC container create path by ensuring wide strings aren’t passed to a narrow format string when constructing Docker bind mount sources.

Changes:

  • Convert sourceFilename (std::wstring) to UTF-8 std::string via wsl::shared::string::WideToMultiByte() before using it in std::format.
  • Keep the bind source construction logic unchanged for directory mounts (no filename suffix).

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.

2 participants