`<locale>`: Facets have wrong type for named locales
Nobody has claimed this yet.
- 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
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 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