Don't require std::locale in chrono.h when FMT_USE_LOCALE is 0 - #4921
Don't require std::locale in chrono.h when FMT_USE_LOCALE is 0#4921nebkat wants to merge 1 commit into
std::locale in chrono.h when FMT_USE_LOCALE is 0#4921Conversation
vitaut
left a comment
There was a problem hiding this comment.
Thanks for the PR. Reducing locale use is a good idea but we shouldn't introduce too much conditional compilation. locale_ref might help with that.
f7aca46 to
a17f354
Compare
|
Reworked along those lines. One gap if you want it covered: |
vitaut
left a comment
There was a problem hiding this comment.
This changes the behavior of {:L} when no locale is passed explicitly. Previously, an empty locale_ref with localized == true resulted in std::locale(), i.e. the current global locale. Now an empty locale_ref is treated as the classic locale.
For example, after std::locale::global(...), fmt::format("{:L}", weekday) should use that global locale, but this change appears to produce the classic English name instead.
a17f354 to
40115a9
Compare
vitaut
left a comment
There was a problem hiding this comment.
Also please rebase and fix merge conflicts.
tm_writer takes a locale_ref and the localized flag instead of a std::locale
reference, and resolves the locale the same way numeric {:L} does: classic
unless localized, otherwise the one passed to the formatting function or the
global one. The facet calls are confined to three shims, so with locale
support disabled nothing pulls in std::locale. get_locale, which existed only
to materialize and own a std::locale, is no longer needed.
The std::tm formatter treated a missing locale argument as the classic locale
rather than the global one, and since fmtlib#4935 routes {:L} on weekday and month
through it, {:L} without a locale argument ignored the global locale for all
calendar types. It now uses the global locale, as numeric {:L} does. Output
with an explicit locale is unchanged. With FMT_USE_LOCALE=0, {:L} no longer
consults the global locale, matching numeric formatting under that option. An
-Os test program loses all 16 of its std::locale and time_put symbols.
40115a9 to
c62f5e0
Compare
|
Rebased and fixed the conflicts with #4935. One thing I ran into while doing that: #4935 dropped the I've made the With |
tm_writertakes alocale_refand the localized flag instead of astd::localereference, and resolves the locale the same way numeric{:L}does: classic unless localized, otherwise the one passed to the formatting function or the global one. The facet calls sit behind three shims, so withFMT_USE_LOCALE=0nothing inchrono.hpulls instd::locale, andget_locale, which existed only to materialize and own one, is gone.Re the global-locale review comment: the
std::tmformatter treated a missing locale argument as the classic locale rather than the global one, and since #4935 routes{:L}onweekday/monththrough it, on current mainfmt::format("{:L}", weekday)afterstd::locale::global(...)produces the classic name regardless of this PR. This PR makes thestd::tmformatter passspecs.localized()like every other path, so{:L}without a locale argument uses the global locale for all chrono types, as numeric{:L}does. That is the only output change withFMT_USE_LOCALE=1: formatting with an explicit locale is byte-identical acrossstd::tm,weekday,month,year_month_day, durations andtime_point,charandwchar_t. WithFMT_USE_LOCALE=0,{:L}no longer consults the global locale, consistent with numeric formatting under that option. A header-only-Ostest program goes from 16std::locale/time_putsymbols to 0 and from 180 kB to 140 kB.Overlaps #4940 (
year_month_dayno longer constructs a locale for its default format) and, for the chrono side, takes the "ignore" option from #4941.