Skip to content

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

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

Fix std::format type mismatch mixing std::wstring and std::string#40201
benhillis wants to merge 1 commit intofeature/wsl-for-appsfrom
copilot/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).

Copilot AI review requested due to automatic review settings April 16, 2026 17:55
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>
@benhillis benhillis force-pushed the copilot/fix/wstring-format-mismatch branch from e98270b to d5f1eb8 Compare April 16, 2026 18:03
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 std::format argument type mismatch in WSLCContainerImpl::Create() when constructing the Docker bind source path for file mounts by ensuring the filename portion is converted from std::wstring to std::string before formatting.

Changes:

  • Convert sourceFilename (std::wstring) to UTF-8 std::string via wsl::shared::string::WideToMultiByte() when building bindSource for file mounts.
  • Reformat the ternary for bindSource into a multi-line expression for readability.

@benhillis benhillis marked this pull request as ready for review April 16, 2026 22:02
@benhillis benhillis requested a review from a team as a code owner April 16, 2026 22:02
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue left a comment

Choose a reason for hiding this comment

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

I don't think this is true (although AIs seem to flag this a lot).

We have a set of custom formatters that handle narrow <-> wide string conversion for us. We use them all across the codebase

@benhillis
Copy link
Copy Markdown
Member Author

Pierre is right on the custom formatters. Copilot was wrong on this one.

@benhillis benhillis closed this Apr 17, 2026
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.

5 participants