microsoft / microsoft/STL

`<system_error>`: `system_error` doesn't honor the current threads's locale

Open
#2,882 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug
"Is there a way to make system_error to honor the current threads’s locale ?
This always prints an error-message according to my default locale."

Command-line test case

C:\Temp>type repro.cpp
#include <clocale>
#include <iostream>
#include <string>

#include <Windows.h>

int main() {
    setlocale(LC_ALL, "");
    SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
    std::string errmsg = std::system_category().message(1);
    std::cout << errmsg << '\n';
}

C:\Temp>cl /nologo /EHsc /W4 /WX repro.cpp
repro.cpp

C:\Temp>.\repro.exe
Неверная функция.

Expected behavior
The message should be in English. (My System Language is Russian)
The program should have a way to change locale of system_error messages.

STL version
git commit hash: https://github.com/microsoft/STL/commit/ef62d3fa0b8e4e2406b9bb74e916e1ca8a1df802

Additional context
DevCom-10098476

Currently we use LOCALE_NAME_SYSTEM_DEFAULT so we don't honor the current threads's locale.
https://github.com/microsoft/STL/blob/ef62d3fa0b8e4e2406b9bb74e916e1ca8a1df802/stl/src/syserror_import_lib.cpp#L43-L59

We can't use GetThreadLocale because it doesn't work with UWP.
Minimum supported client | Windows 2000 Professional [desktop apps only]

I recently changed the function but previous version didn't respect the current threads's locale either: https://godbolt.org/z/37f44nahM

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 stl/src/syserror_import_lib.cpp at lines 43-59 and reproduce the behavior using the Windows repro.cpp command-line example. Investigate how the current thread locale can be obtained while preserving UWP support, then verify that std::system_category().message(1) follows the thread locale rather than the system default.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.