microsoft / microsoft/STL

`<locale>`: Facets have wrong type for named locales

Open
#5,394 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

[locale.facet]/5 suggests that a locale constructed with constructor locale(const char*) should provide facets of type [facet]_byname, but MSVC STL constructs facets of type [facet] instead.

Test case

#include <iostream>
#include <locale>

using namespace std;

int main() {
    locale loc("en_US");
    const auto& coll = use_facet<collate<char>>(loc);
    cout << typeid(coll).name();
}

https://godbolt.org/z/a556r5czc

Expected behavior

This should print class std::collate_byname<char>, but actually prints class std::collate<char>.

Additional context

This bug means that we can't implement the resolution of LWG-4186 (#5291) as-is.

[locale.category]/3 seems to suggest that [facet] and not [facet]_byname is the correct type for the C locale returned by locale::classic(). But this creates some tension in the spec: [locale.facet]/5 suggests that locale(const char*) should construct [facet]_byname facets, while [locale.statics]/5 says that locale::classic() should return a locale equivalent to locale("C"). Are the locales still considered equivalent if the facet types aren't the same?

Note that libc++ solves this by producing C locales with different facet types for locale("C") and locale::classic(): https://godbolt.org/z/nzW4qxja1

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 reproducing the provided locale and typeid test, then inspect the MSVC STL locale and facet implementation. Compare the behavior with [locale.facet]/5, [locale.category]/3, and [locale.statics]/5, including the C locale distinction. Done means the named-locale constructor provides the required byname facet types without breaking locale::classic() behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
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.