Should `std::error_code::message` respect the locale set by the user?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
In our program, we use std::setlocale(LC_ALL, ".UTF8"); to support UTF-8 encoding, as noted in the Microsoft documentation. However, when certain C++ STL functions fail, their message() outputs are not in UTF-8.
After investigating the source code, I found that the error messages are always formatted according to the system's default locale, as shown in this STL implementation:
https://github.com/microsoft/STL/blob/e36ee6c2b9bc6f5b1f70776c18cf5d3a93a69798/stl/src/syserror_import_lib.cpp#L38-L54
While it would be acceptable if the system locale used UTF-8 as the codepage, allowing the messages to be correctly printed to log files, this is not the case. There is a "Beta: Use Unicode UTF-8 for worldwide language support" setting in the Region settings, which does the job correctly, but toggling that setting requires a reboot, which is not acceptable for our requirements.
Question
Should the std::error_code::message function respect the locale set by the user (e.g., via std::setlocale), or should it continue to use the system's default locale? If the former, is there a plan to implement this behavior in the Microsoft STL implementation?
Related Information
- I learned that the locale is by default set across the whole program, unless specified by configthreadlocale, from the Microsoft documentation.
- The issue of system_error not honoring the current thread's locale is mentioned in this issue.
Please let me know if you need any additional information or clarification.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read stl/src/syserror_import_lib.cpp at the linked lines and review related issue #2882 first. Done means reaching a maintainer-backed decision on whether std::error_code::message should use the user or thread locale, with the implementation plan or rationale recorded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- localization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100