microsoft / microsoft/STL

`<filesystem>`: Problem with `filesystem::path` converting to utf8 when it shouldn't.

Open
#5,773 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

filesystem question
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug

Sometimes this pair of values are inconsistent, causing not an exception where it should be an exception if a filesystem::path containing non-1252 characters is converted using path::string()

        int cp = GetACP();                         // returns 1252
        auto p = __std_fs_code_page();    // returns _Utf8

This combination should never occur as string() uses __std_fs_code_page to check if it should convert to UTF8 or the current code page.

In case __std_fs_code_page is supposed to return _Utf8 if compiled with /utf8 (which we do) this is a bug in itself: string() converts to the current locale's narrow character encoding, not to the execution character set.

We only get this behaviour on some builds which suggests inlining that's not inlined could be involved but __std_fs_code_page just calls a function in a dll so I don't think so.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported interaction between filesystem::path::string() and __std_fs_code_page(), comparing builds where GetACP() returns 1252 and __std_fs_code_page() returns _Utf8. Investigate whether /utf8, inlining, or the DLL call explains the inconsistent values. Done means the behavior is reproduced and the conversion consistently throws or uses the intended encoding.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.