
On Friday, December 30, 2011 08:48:59 Beman Dawes wrote:
I can see two possible fixes:
(A) Use function scope locale initialization, using boost/detail/lightweight_mutex.hpp to prevent data races.
(B) Use namespace scope locale initialization, defaulting the codecvt facet to UTF-8 if std::locale("") throws.
The advantage of (B) is that path always initializes without throwing, and that's what users seem to expect. The initialization is correct for all those whose environments are configured correctly, and for those uses who want UTF-8 even if their environments are misconfigured. The POSIX users who prefer an exception on a misconfigured environment can always add a std::locale("") at the start of main().
Comments or opinions?
Can't locale be initialized within a call_once initializer? This seems to be a natural solution for function-local static initializations.