-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
time_put_byname seems to use the system code page even if the locale name contains .UTF-8.
For example, in the ja_JP.UTF-8 locale, "土曜日" (which means "Saturday") is encoded as "\xCD\xC1\xEA\xD7\xC8\xD5" on my computer, but it's UTF-8 representation is "\xE5\x9C\x9F\xE6\x9B\x9C\xE6\x97\xA5".
The libcxx test std/localization/locale.categories/category.time/locale.time.put.byname/put1.pass.cpp expects the output to be encoded in UTF-8 in this case.
time_put_byname is super old and rarely used, and fixing this would be a behavior change. I don't know if it's worth the trouble.
Command-line test case
D:\test>type test-time-put-byname.cpp
#include <cassert>
#include <ctime>
#include <iostream>
#include <locale>
class my_facet : public std::time_put_byname<char, char*>
{
public:
explicit my_facet(const std::string& nm, std::size_t refs = 0)
: time_put_byname(nm, refs) {}
};
int main() {
const my_facet f("ja_JP.UTF-8", 1);
std::tm t = {};
t.tm_wday = 6;
std::ios str(nullptr);
{
char buf[200];
char* iter = f.put(buf, str, '*', &t, 'A');
std::cout.setf(std::ios::hex, std::ios::basefield);
for (char* p = buf; p != iter; ++p) {
std::cout << (int)(unsigned char)*p << ' ';
}
std::cout << '\n';
}
}D:\test>cl /EHsc test-time-put-byname.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35725 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
test-time-put-byname.cpp
Microsoft (R) Incremental Linker Version 14.50.35725.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test-time-put-byname.exe
test-time-put-byname.obj
D:\test>test-time-put-byname.exe
cd c1 ea d7 c8 d5
Expected behavior
The output is e5 9c 9f e6 9b 9c e6 97 a5.
STL version
Additional context
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working