diff --git a/src/bun.js/bindings/EncodingTables.h b/src/bun.js/bindings/EncodingTables.h index a7b7dec52a..23179c1958 100644 --- a/src/bun.js/bindings/EncodingTables.h +++ b/src/bun.js/bindings/EncodingTables.h @@ -58,14 +58,18 @@ inline void checkEncodingTableInvariants() {} struct CompareFirst { template bool operator()(const TypeA& a, const TypeB& b) { - return a.first < b.first; + // Use std::common_type to safely compare different character types (e.g., char16_t vs char32_t) + using CommonType = std::common_type_t; + return static_cast(a.first) < static_cast(b.first); } }; struct EqualFirst { template bool operator()(const TypeA& a, const TypeB& b) { - return a.first == b.first; + // Use std::common_type to safely compare different character types (e.g., char16_t vs char32_t) + using CommonType = std::common_type_t; + return static_cast(a.first) == static_cast(b.first); } }; @@ -114,20 +118,23 @@ template bool sortedFirstsAreUnique(const CollectionTyp template static auto findFirstInSortedPairs(const CollectionType& collection, const KeyType& key) -> std::optionalsecond)> { + using CollectionKeyType = decltype(std::begin(collection)->first); if constexpr (std::is_integral_v) { - if (key != decltype(std::begin(collection)->first)(key)) + if (static_cast(static_cast(key)) != key) return std::nullopt; } auto iterator = std::lower_bound(std::begin(collection), std::end(collection), makeFirstAdapter(key), CompareFirst {}); - if (iterator == std::end(collection) || key < iterator->first) + using CommonType = std::common_type_t; + if (iterator == std::end(collection) || static_cast(key) < static_cast(iterator->first)) return std::nullopt; return iterator->second; } template static auto findInSortedPairs(const CollectionType& collection, const KeyType& key) -> std::span> { + using CollectionKeyType = decltype(std::begin(collection)->first); if constexpr (std::is_integral_v) { - if (key != decltype(std::begin(collection)->first)(key)) + if (static_cast(static_cast(key)) != key) return {}; } return std::ranges::equal_range(collection, makeFirstAdapter(key), CompareFirst {}); diff --git a/src/bun.js/bindings/TextCodecCJK.cpp b/src/bun.js/bindings/TextCodecCJK.cpp index b09ee61889..eee9a134b9 100644 --- a/src/bun.js/bindings/TextCodecCJK.cpp +++ b/src/bun.js/bindings/TextCodecCJK.cpp @@ -890,7 +890,7 @@ static const GB18030EncodeIndex& gb18030EncodeIndex() // https://unicode-org.atlassian.net/browse/ICU-22357 // The 2-byte values are handled correctly by values from gb18030() // but these need to be exceptions from gb18030Ranges(). -static std::optional gb18030AsymmetricEncode(char16_t codePoint) +static std::optional gb18030AsymmetricEncode(char32_t codePoint) { switch (codePoint) { case 0xE81E: