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

Avoid unwanted sign extensions from MSVC in is_utf8. #2297

Merged
merged 2 commits into from
May 19, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,11 @@ FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char micro[] = "\u00B5";

constexpr bool is_utf8() {
return FMT_UNICODE ||
(sizeof(micro) == 3 && micro[0] == 0xC2 && micro[1] == 0xB5);
// avoid buggy sign extensions in MSVC's constant evaluation mode
// https://developercommunity.visualstudio.com/t/C-difference-in-behavior-for-unsigned/1233612
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please make it a proper sentence:

  // Avoid buggy sign extensions in MSVC's constant evaluation mode
  // https://developercommunity.visualstudio.com/t/C-difference-in-behavior-for-unsigned/1233612.

using uchar = unsigned char;
return FMT_UNICODE || (sizeof(micro) == 3 && uchar{micro[0]} == 0xC2 &&
uchar{micro[1]} == 0xB5);
mwinterb marked this conversation as resolved.
Show resolved Hide resolved
}
FMT_END_DETAIL_NAMESPACE

Expand Down