Skip to content

Don't require std::locale in chrono.h when FMT_USE_LOCALE is 0 - #4921

Open
nebkat wants to merge 1 commit into
fmtlib:mainfrom
nebkat:chrono-no-locale
Open

Don't require std::locale in chrono.h when FMT_USE_LOCALE is 0#4921
nebkat wants to merge 1 commit into
fmtlib:mainfrom
nebkat:chrono-no-locale

Conversation

@nebkat

@nebkat nebkat commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

tm_writer takes a locale_ref, which is already empty without locale support, so the facet calls compile away and get_locale is no longer needed. Output is unchanged; an -Os test program loses all 16 of its std::locale and time_put symbols and ~4.3kB.

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

tm_writer takes a locale_ref, which is already empty without locale support,
instead of a std::locale reference, and the facet calls are confined to three
shims. get_locale, which existed only to materialize and own a std::locale,
is no longer needed. Output is unchanged; an -Os test program loses all 16 of
its std::locale and time_put symbols, and the default build gets slightly
smaller as well.
@nebkat

nebkat commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Reworked along those lines. tm_writer now takes a locale_ref, which is already empty when locale support is off, so the conditional compilation collapses to one block of shims next to write(), and get_locale — the only reason chrono.h owned a std::locale — is gone entirely. Rebased on main.

One gap if you want it covered: nolocale-test only compiles src/format.cc, so nothing exercises chrono.h with FMT_USE_LOCALE=0. Happy to add a TU that includes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants