[Bug 251674] libc++: std::wcout does not use global locale set via setlocale()

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Tue Dec 8 10:27:54 UTC 2020


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=251674

--- Comment #8 from Dimitry Andric <dim at FreeBSD.org> ---
See e.g.:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/localization.html#locale.impl.c

which says:

> From Josuttis, p. 697-698, which says, that "there is only *one*
> relation (of the C++ locale mechanism) to the C locale mechanism: the
> global C locale is modified if a named C++ locale object is set as
> the global locale" (emphasis Paolo), that is:
>
> std::locale::global(std::locale(""));
>
> affects the C functions as if the following call was made:
>
> std::setlocale(LC_ALL, "");
>
> On the other hand, there is *no* vice versa, that is, calling
> setlocale has *no* whatsoever on the C++ locale mechanism, in
> particular on the working of locale(""), which constructs the locale
> object from the environment of the running program, that is, in
> practice, the set of LC_ALL, LANG, etc. variable of the shell.

The above wording is also found in e.g. the C++11 standard, in
[locale.statics]:

> static locale global(const locale& loc);
>
> 1. Sets the global locale to its argument.
>
> 2. Effects: Causes future calls to the constructor locale() to return
>    a copy of the argument. If the argument has a name, does
>
>      std::setlocale(LC_ALL, loc.name().c_str());
>
>    otherwise, the efect on the C locale, if any, is
>    implementation-defined. No library function other than
>    locale::global() shall afect the value returned by locale().
>    [Note: See 22.6 for data race considerations when setlocale is
>    invoked.]
>
> 3. Returns: The previous value of locale().

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list