question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG]: unicode handling maybe broken

See original GitHub issue

Describe the bug

In a tweet someone posted https://godbolt.org/z/fdWx983sa which tries to std::wcout some unicode things.

Steps to reproduce

Click the link and see the output is SomeText F F

Expected behavior

The output should contain unicode chars, something like SomeText Φ Φ"

Reproduction link

https://godbolt.org/z/fdWx983sa

Screenshots

Not applicable

Operating System

No response

Browser version

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
partoufcommented, Jan 24, 2022

Dug a bit into cppreference and the GCC testsuite, and they basically do this too when testing std::wcout with unicode characters

    std::locale loc("en_US.UTF-8");
    std::locale::global(loc);

e.g. https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/testsuite/27_io/objects/wchar_t/11.cc

They only seem to not use it in situations with just ASCII.

There’s also examples on the internet calling std::imbue(std::wcout, loc), but that only applies to language related formatting as far as I can tell. The global() call also affects the encoding/decoding.

It might be that it’s a GCC bug that they haven’t noticed because it’s never tested without global() - but that’s just speculation from my perspective. I don’t know what the standard says on this subject, but I bet it’s one of those “implementation defined” kind of things.

0reactions
deanturpincommented, Jan 24, 2022

fmt::print also starts working with the addition of setlocale.

int main() {

  setlocale(LC_ALL, "en_US.utf8");

  const auto out = std::wstring{L"cya \u03A6"};
  fmt::print(L"{}\n", out);
}

https://godbolt.org/z/xKWjTs6z7

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug Report: Unicode handling error in Team Name Addition ...
Summary: Adding a new team name doesn't work as expected in Pipedrive. Steps to reproduce: In Pipedrive app, go to Settings > Manage...
Read more >
broken GitLab syntax: labels with unicode characters fail to ...
It is a ~bug. I gave unicode chars as an example. There may be other examples which break the rendering (e.g. usernames in...
Read more >
Unicode characters broken when __MSG_... in css file
Actual results: Unicode characters broken, regardless of the css or html encoding. Expected results: Correctly handle characters.
Read more >
Divides a string into substrings at each Unicode whitespace ...
According to the docs, String.split/1… ... Possible bug in String.split/1's handling of Unicode whitespace? ... Maybe others too? No-break ...
Read more >
Fixing broken UTF-8 encoding - php - Stack Overflow
A quick look seems to suggest that your strings might have been "double" utf-8 encoded. I.e. encoded in utf-8, those bytes taken as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found