fuzzer: modernize FuzzedDataProvider conversions (#177794) This change modernizes FuzzedDataProvider.h now that C++17+ is standard in LLVM. Replace the runtime if with if constexpr in ConvertUnsignedToSigned Make the unsigned/signed comparison explicit by casting TS::max() to TU GitOrigin-RevId: 1ce7a8159352e903f1dab50ff340fcd32a84cf63
diff --git a/FuzzedDataProvider.h b/FuzzedDataProvider.h index 33ffa8b..5fab0c4 100644 --- a/FuzzedDataProvider.h +++ b/FuzzedDataProvider.h
@@ -380,13 +380,13 @@ static_assert(!std::numeric_limits<TU>::is_signed, "Source type must be unsigned."); - // TODO(Dor1s): change to `if constexpr` once C++17 becomes mainstream. - if (std::numeric_limits<TS>::is_modulo) + if constexpr (std::numeric_limits<TS>::is_modulo) return static_cast<TS>(value); // Avoid using implementation-defined unsigned to signed conversions. // To learn more, see https://stackoverflow.com/questions/13150449. - if (value <= std::numeric_limits<TS>::max()) { + constexpr auto TS_max = static_cast<TU>(std::numeric_limits<TS>::max()); + if (value <= TS_max) { return static_cast<TS>(value); } else { constexpr auto TS_min = std::numeric_limits<TS>::min();