<locale>: Creating a new locale with a custom facet doesn't work correctly
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Describe the bug
I tried to make a workaround to solve an old bug in STL, which isn't fixed after some years :(
(DevCom-51443).
Just created a ctype facet with an own table. But when I create a new locale with my custom facet, the locale change from german to classic (i think it's classic locale). For simplicity i add in demo code std::money_get facet instead of my custom ctype facet, but it's the same behaviour.
I´m using VS2019 with latest update (16.3.7)
#include <iostream>
#include <locale>
int main()
{
std::locale loc_ger("de");
std::locale loc_en("en");
const auto &f = std::use_facet<std::money_get<char>>(loc_en);
std::locale loc = std::locale(loc_ger, &f);
std::locale::global(loc);
// std::cout.imbue(loc); // tried with this line too
std::cout << "üöäÜÖÄ" << std::endl;
}
output shall be:
"üöäÜÖÄ"
but output is:
"³÷õ▄Í─"
I did the same test on https://rextester.com/l/cpp_online_compiler_gcc. there i got the correct output.
Greets from germany
Helmut
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
Start by running the provided main program with VS2019 and compare the output after constructing std::locale loc from loc_ger and the std::money_get facet from loc_en. Inspect the std::locale construction, std::locale::global, and std::cout imbue behavior involved in facet replacement. Done means the custom-facet locale preserves the expected German character output instead of producing corrupted characters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- localization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100