mirror of
https://github.com/shadps4-emu/ext-fmt.git
synced 2025-02-20 02:03:16 +00:00
Avoid unwanted sign extensions from MSVC in is_utf8.
Microsoft's constexpr evaluator treats the type of micro[0] and micro[1] as plain char, and so sign extends before comparing them to ints. The normal compiler, including the optimizer, does not fail in this way, so this is merely a "future proof" change in case someone uses is_utf8() in a constant expression.
This commit is contained in:
parent
13e652939b
commit
be48f4d657
@ -395,8 +395,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
|
||||
using uchar = unsigned char;
|
||||
return FMT_UNICODE || (sizeof(micro) == 3 && uchar{micro[0]} == 0xC2 &&
|
||||
uchar{micro[1]} == 0xB5);
|
||||
}
|
||||
FMT_END_DETAIL_NAMESPACE
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user