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

<print>: std::print may incorrectly display multibyte characters #5239

Open
JMazurkiewicz opened this issue Jan 15, 2025 · 1 comment
Open
Labels
bug Something isn't working

Comments

@JMazurkiewicz
Copy link
Contributor

JMazurkiewicz commented Jan 15, 2025

Describe the bug

std::print incorrectly displays characters that take two or more bytes, when they appear at the boundary of 256 bytes long chunk. This happens only when stdout is a console and nonlocking formatting is used.

Command-line test case

#include <print>

int main() {
  std::string str(255, 'a');
  str.append("ą"); // U+0105
  std::println("{}", str);
}
PS E:\stl> .\out\x64\set_environment.ps1
PS E:\stl> cl /std:c++latest /utf-8 .\print-bug.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.43.34618 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

print-bug.cpp
Microsoft (R) Incremental Linker Version 14.43.34618.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:print-bug.exe
print-bug.obj
PS E:\stl> .\print-bug.exe
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa��

Expected output

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaą

STL version

This bug was introduced in #4821.

@CaseyCarter CaseyCarter added the bug Something isn't working label Jan 15, 2025
@jovibor
Copy link
Contributor

jovibor commented Jan 16, 2025

Works as expected if compiled with the /utf-8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants