microsoft / microsoft/STL

<locale>: Creating a new locale with a custom facet doesn't work correctly

Open
#245 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug info needed
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.