Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc++ put_time outputs in wrong language on OpenBSD 7.4 #71871

Closed
seanm opened this issue Nov 9, 2023 · 4 comments
Closed

libc++ put_time outputs in wrong language on OpenBSD 7.4 #71871

seanm opened this issue Nov 9, 2023 · 4 comments
Labels
invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. platform:openbsd

Comments

@seanm
Copy link

seanm commented Nov 9, 2023

On OpenBSD 7.4 (newest) on x86_64 with its default / built-in clang:

$ clang++ --version
OpenBSD clang version 13.0.0
Target: amd64-unknown-openbsd7.4
Thread model: posix
InstalledDir: /usr/bin

This reduced C++ case:

#include <ctime>
#include <iomanip>
#include <iostream>

int main() {
  std::time_t t = std::time(nullptr);
  std::cout.imbue(std::locale("es_ES.UTF-8"));
  std::cout << std::put_time(std::localtime(&t), "%a");
}

When run on a Tuesday, gives "Tue". It should be outputting "mar", for Spanish "martes" (meaning Tuesday). That's what I get with macOS and FreeBSD.

Giving the output in the wrong language looks like a bug. It should either respect the locale or give an error (https://godbolt.org/z/KoW8YPqfc) when constructing an unsupported locale.

I don't know if this is a libc++ bug or an OpenBSD bug...

@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 9, 2023
@ldionne ldionne added the invalid Resolved as invalid, i.e. not a bug label Nov 16, 2023
@ldionne
Copy link
Member

ldionne commented Nov 16, 2023

I think this is extremely likely to be an OpenBSD bug, since the C++ localization library generally just forwards to the underlying OS localization functions. Can you reproduce on OpenBSD with the following pure C code?

#include <stdio.h>
#include <locale.h>
#include <time.h>
#include <wchar.h>

int main() {
  setlocale(LC_TIME, "es_ES.UTF-8");
  wchar_t str[100];
  time_t t = time(NULL);
  wcsftime(str, 100, L"%a", localtime(&t));
  wprintf(L"%ls\n", str);
}

I'll close this tentatively, but please reopen if the above code behaves correctly on OpenBSD but the corresponding C++ code doesn't.

@ldionne ldionne closed this as completed Nov 16, 2023
@seanm
Copy link
Author

seanm commented Nov 16, 2023

Thanks @ldionne. You are correct, it occurs with that code too. I'll report to the OpenBSD folks.

@ischwarze
Copy link

This is not a bug in LLVM but intentional behaviour in the OpenBSD C library for security reasons and well documented on our locale(1), setlocale(3), wcsftime(3), and strftime(3) manual pages. Please close this ticket as invalid.

@vitaut
Copy link

vitaut commented Nov 16, 2023

Thanks for clarifying that this is intentional behavior in the C library implementation on OpenBSD but this brings a question whether relying on it in the C++ library is conforming. Perhaps libc++ should report an error when using intentionally disabled C locale functionality or use a different locale implementation on OpenBSD. Note that C++ locales are separate so pretty much nothing in locale(1), setlocale(3), wcsftime(3), and strftime(3) applies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Resolved as invalid, i.e. not a bug libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. platform:openbsd
Projects
None yet
Development

No branches or pull requests

5 participants