| Summary: | C++ std::locale support is broken | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Yuri Karaban <tech> |
| Component: | standards | Assignee: | freebsd-standards (Nobody) <standards> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | CC: | theraven |
| Priority: | Normal | ||
| Version: | 8.1-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
In FreeBSD 9.1, the POSIX2008 extended locale additions (and some Darwin extensions) were added to libc. libc++ uses them and we pass almost all of its locale-specific tests (the remainder need triaging, but at least some are bugs in the tests). |
Standard C++ library, libstdc++, compiled with "generic" locale support. So only "C" and "POSIX" locales are supported. Setting any other locale will throw the runtime_error exception "locale::facet::_S_create_c_locale name not valid". Though locale name is valid and works with setlocale(3). On Linux libstdc++ is using "gnu" locale configuration. Which takes use of newlocale(3)/uselocale(3)/freelocale(3)/... POSIX calls. FreeBSD does not support these calls so it is not possible to use "gnu" configuration. Since C++ standard allow several locale instances to coexists simultaneously, it must be not possible to implement C++ locales in terms of setlocale(3). There are two possible solutions: 1. Implement locale related functions in FreeBSD C Library. This option is preferred: supporting standard functions is always a plus and having these function it is possible to use existing locale model in libstdc++. 2. Implement custom locale support for FreeBSD in libstdc++. Advantage that standard C library would be untouched. But on the other hand, there are many disadvantages (to create libstdc++ locale model from scratch; difficult to implement in terms of setlocale, means use of some hacks with libc internals). PS. Locale support is really important. C++ programs which use locale is unusable on FreeBSD and there is no workaround. How-To-Repeat: Compile and run following C++ code: #include <locale> int main() { std::locale("en_US.UTF-8"); }