<xloctime>: Fix time_put::do_put to correctly handle %c and %r formatting in "C" locale#6299
<xloctime>: Fix time_put::do_put to correctly handle %c and %r formatting in "C" locale#6299ferhatgec wants to merge 2 commits into
<xloctime>: Fix time_put::do_put to correctly handle %c and %r formatting in "C" locale#6299Conversation
|
This needs to be clang-formatted with the current version of Clang shipping in VS Insiders (currently Clang 22.1.3). We recommend configuring your editor to use clang-format; if you use VSCode, our repo will enable format-on-save for C++ files. The configuration setting for the C/C++ Extension to hook up clang-format is |
…rmat in C locale
|
Sorry, my bad. Didn't realize my IDE was using my own |
|
It seems the CI is failing because assert(format(STR("{:%c, %x, %X}"), ltf) == STR("04/19/21 01:02:03, 04/19/21, 01:02:03"));with: assert(format(STR("{:%c, %x, %X}"), ltf) == STR("Mon Apr 19 01:02:03 2021, 04/19/21, 01:02:03"));and replacing: assert(format(STR("{:%c, %x, %X}"), zt) == STR("04/19/21 08:16:17, 04/19/21, 08:16:17"));with: assert(format(STR("{:%c, %x, %X}"), zt) == STR("Mon Apr 19 08:16:17 2021, 04/19/21, 08:16:17"));Doing these seems to resolve the issue, at least on my PC. |
Fixes #6134.
Description
The C standard requires the
%cand%rspecifiers to be equivalent to%a %b %e %T %Yand%I:%M:%S %prespectively in the "C" locale (N3220 § 7.29.3.5/7). While the standard Cstrftimemight handle this correctly, the internal UCRT functions_Strftimeand_Wcsftimeused by<xloctime>do not provide this expected output. This causes a mismatch when usingstd::time_put::do_put.This PR introduces a workaround in
time_put::do_put. When_Iosbase.getloc() == locale::classic(), it explicitly overrides the format strings for the%cand%rspecifiers with the standard-mandated sequences before passing them to_Strftime/_Wcsftime. Since this problem only occurs in "C" locale, this workaround resolves the issue without affecting others.Testing
std/localization/locale.categories/category.time/locale.time.put/locale.time.put.members/put2.pass.cppfromtests/libcxx/expected_results.txt.