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

Fix boost min/max guidelines violations #254

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion include/boost/charconv/detail/emulated128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ struct numeric_limits<boost::charconv::detail::uint128>
BOOST_ATTRIBUTE_UNUSED static constexpr boost::charconv::detail::uint128 infinity() { return 0; }
BOOST_ATTRIBUTE_UNUSED static constexpr boost::charconv::detail::uint128 quiet_NaN() { return 0; }
BOOST_ATTRIBUTE_UNUSED static constexpr boost::charconv::detail::uint128 signaling_NaN() { return 0; }
BOOST_ATTRIBUTE_UNUSED static constexpr boost::charconv::detail::uint128 denorm_min() { return 0; }
BOOST_ATTRIBUTE_UNUSED static constexpr boost::charconv::detail::uint128 (denorm_min)() { return 0; }
};

} // Namespace std
Expand Down
6 changes: 3 additions & 3 deletions include/boost/charconv/detail/fallback_routines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ from_chars_result from_chars_strtod_impl(const char* first, const char* last, T&
#ifndef __INTEL_LLVM_COMPILER
if (return_value == HUGE_VALF)
#else
if (return_value >= std::numeric_limits<T>::max())
if (return_value >= (std::numeric_limits<T>::max)())
#endif
{
r = {last, std::errc::result_out_of_range};
Expand All @@ -171,7 +171,7 @@ from_chars_result from_chars_strtod_impl(const char* first, const char* last, T&
#ifndef __INTEL_LLVM_COMPILER
if (return_value == HUGE_VAL)
#else
if (return_value >= std::numeric_limits<T>::max())
if (return_value >= (std::numeric_limits<T>::max)())
#endif
{
r = {last, std::errc::result_out_of_range};
Expand All @@ -184,7 +184,7 @@ from_chars_result from_chars_strtod_impl(const char* first, const char* last, T&
#ifndef __INTEL_LLVM_COMPILER
if (return_value == HUGE_VALL)
#else
if (return_value >= std::numeric_limits<T>::max())
if (return_value >= (std::numeric_limits<T>::max)())
#endif
{
r = {last, std::errc::result_out_of_range};
Expand Down
4 changes: 2 additions & 2 deletions include/boost/charconv/detail/fast_float/parse_number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ BOOST_FORCEINLINE bool rounds_to_nearest() noexcept {
// The volatile keywoard prevents the compiler from computing the function
// at compile-time.
// There might be other ways to prevent compile-time optimizations (e.g., asm).
// The value does not need to be std::numeric_limits<float>::min(), any small
// The value does not need to be (std::numeric_limits<float>::min)(), any small
// value so that 1 + x should round to 1 would do (after accounting for excess
// precision, as in 387 instructions).
static volatile float fmin = std::numeric_limits<float>::min();
static volatile float fmin = (std::numeric_limits<float>::min)();
float fmini = fmin; // we copy it so that it gets loaded at most once.
//
// Explanation:
Expand Down
6 changes: 3 additions & 3 deletions src/from_chars_float_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ from_chars_result from_chars_float_impl(const char* first, const char* last, T&
#ifndef __INTEL_LLVM_COMPILER
if (return_val == HUGE_VALF || return_val == -HUGE_VALF)
#else
if (return_val >= std::numeric_limits<T>::max() || return_val <= std::numeric_limits<T>::lowest())
if (return_val >= (std::numeric_limits<T>::max)() || return_val <= std::numeric_limits<T>::lowest())
#endif
{
value = return_val;
Expand All @@ -127,7 +127,7 @@ from_chars_result from_chars_float_impl(const char* first, const char* last, T&
#ifndef __INTEL_LLVM_COMPILER
if (return_val == HUGE_VAL || return_val == -HUGE_VAL)
#else
if (return_val >= std::numeric_limits<T>::max() || return_val <= std::numeric_limits<T>::lowest())
if (return_val >= (std::numeric_limits<T>::max)() || return_val <= std::numeric_limits<T>::lowest())
#endif
{
value = return_val;
Expand All @@ -148,7 +148,7 @@ from_chars_result from_chars_float_impl(const char* first, const char* last, T&
#ifndef __INTEL_LLVM_COMPILER
if (return_val == HUGE_VALL || return_val == -HUGE_VALL)
#else
if (return_val >= std::numeric_limits<T>::max() || return_val <= std::numeric_limits<T>::lowest())
if (return_val >= (std::numeric_limits<T>::max)() || return_val <= std::numeric_limits<T>::lowest())
#endif
{
value = return_val;
Expand Down
6 changes: 3 additions & 3 deletions test/from_chars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ void test_128bit_int()
BOOST_TEST(v1 == test_value);

#ifdef __GLIBCXX_TYPE_INT_N_0
BOOST_TEST(std::numeric_limits<T>::max() > static_cast<T>(std::numeric_limits<unsigned long long>::max()));
BOOST_TEST((std::numeric_limits<T>::max)() > static_cast<T>((std::numeric_limits<unsigned long long>::max)()));
#else
BOOST_IF_CONSTEXPR (std::is_same<T, boost::int128_type>::value)
{
BOOST_TEST(BOOST_CHARCONV_INT128_MAX > static_cast<T>(std::numeric_limits<unsigned long long>::max()));
BOOST_TEST(BOOST_CHARCONV_INT128_MAX > static_cast<T>((std::numeric_limits<unsigned long long>::max)()));
}
else
{
BOOST_TEST(BOOST_CHARCONV_UINT128_MAX > static_cast<T>(std::numeric_limits<unsigned long long>::max()));
BOOST_TEST(BOOST_CHARCONV_UINT128_MAX > static_cast<T>((std::numeric_limits<unsigned long long>::max)()));
}
#endif
}
Expand Down
12 changes: 6 additions & 6 deletions test/limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ template<typename T> void test_integral()
test_odr_use( &boost::charconv::limits<T>::max_chars10 );
test_odr_use( &boost::charconv::limits<T>::max_chars );

test_integral( std::numeric_limits<T>::min() );
test_integral( std::numeric_limits<T>::max() );
test_integral( (std::numeric_limits<T>::min)() );
test_integral( (std::numeric_limits<T>::max)() );
}

template<typename T> void test_floating_point( T value )
Expand Down Expand Up @@ -205,10 +205,10 @@ template<typename T> void test_floating_point()
test_odr_use( &boost::charconv::limits<T>::max_chars10 );
test_odr_use( &boost::charconv::limits<T>::max_chars );

test_floating_point( std::numeric_limits<T>::min() );
test_floating_point( -std::numeric_limits<T>::min() );
test_floating_point( std::numeric_limits<T>::max() );
test_floating_point( -std::numeric_limits<T>::max() );
test_floating_point( (std::numeric_limits<T>::min)() );
test_floating_point( -(std::numeric_limits<T>::min)() );
test_floating_point( (std::numeric_limits<T>::max)() );
test_floating_point( -(std::numeric_limits<T>::max)() );
}

int main()
Expand Down
12 changes: 6 additions & 6 deletions test/roundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ template<class T> void test_roundtrip_uint128( int base )

template<class T> void test_roundtrip_bv( int base )
{
test_roundtrip_integers(std::numeric_limits<T>::min(), base);
test_roundtrip_integers(std::numeric_limits<T>::max(), base);
test_roundtrip_integers((std::numeric_limits<T>::min)(), base);
test_roundtrip_integers((std::numeric_limits<T>::max)(), base);
}

#ifdef BOOST_CHARCONV_HAS_INT128
Expand Down Expand Up @@ -388,10 +388,10 @@ template <> void test_roundtrip<long double>(long double value, boost::charconv:

template<class T> void test_roundtrip_bv()
{
test_roundtrip( std::numeric_limits<T>::min() );
test_roundtrip( -std::numeric_limits<T>::min() );
test_roundtrip( std::numeric_limits<T>::max() );
test_roundtrip( +std::numeric_limits<T>::max() );
test_roundtrip( (std::numeric_limits<T>::min)() );
test_roundtrip( -(std::numeric_limits<T>::min)() );
test_roundtrip( (std::numeric_limits<T>::max)() );
test_roundtrip( +(std::numeric_limits<T>::max)() );
}

//
Expand Down
4 changes: 2 additions & 2 deletions test/test_128bit_emulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ void test_memcpy()

void test_limits()
{
BOOST_TEST(std::numeric_limits<uint128>::min() == 0);
BOOST_TEST(std::numeric_limits<uint128>::max() == uint128(UINT64_MAX, UINT64_MAX));
BOOST_TEST((std::numeric_limits<uint128>::min)() == 0);
BOOST_TEST((std::numeric_limits<uint128>::max)() == uint128(UINT64_MAX, UINT64_MAX));
BOOST_TEST(std::numeric_limits<uint128>::is_signed == false);
BOOST_TEST(std::numeric_limits<uint128>::is_integer == true);
BOOST_TEST(std::numeric_limits<uint128>::digits == CHAR_BIT * sizeof(std::uint64_t) * 2);
Expand Down
4 changes: 2 additions & 2 deletions test/test_128bit_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ void test128()
BOOST_TEST_EQ(r1.high, UINT64_C(0));
BOOST_TEST_EQ(r1.low, UINT64_C(1));

auto r2 = boost::charconv::detail::umul128(10, std::numeric_limits<std::uint64_t>::max());
auto r2 = boost::charconv::detail::umul128(10, (std::numeric_limits<std::uint64_t>::max)());
BOOST_TEST_EQ(r2.high, UINT64_C(9));
BOOST_TEST_EQ(r2.low, UINT64_C(18446744073709551606));

auto r3 = boost::charconv::detail::umul128(std::numeric_limits<std::uint64_t>::max(), std::numeric_limits<std::uint64_t>::max());
auto r3 = boost::charconv::detail::umul128((std::numeric_limits<std::uint64_t>::max)(), (std::numeric_limits<std::uint64_t>::max)());
BOOST_TEST_EQ(r3.high, UINT64_C(18446744073709551614));
BOOST_TEST_EQ(r3.low, UINT64_C(1));
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void test_integer()
BOOST_TEST(r3.ec == std::errc::invalid_argument);

// Get the maximum value of the significant type
constexpr auto max_sig_v = std::numeric_limits<decltype(significand)>::max();
constexpr auto max_sig_v = (std::numeric_limits<decltype(significand)>::max)();
char max_sig_buf[boost::charconv::limits<decltype(significand)>::max_chars10 + 1u];
const auto r4 = boost::charconv::to_chars(max_sig_buf + 1, max_sig_buf + sizeof(max_sig_buf), max_sig_v);
if (BOOST_TEST(r4)) {
Expand Down
6 changes: 3 additions & 3 deletions test/to_chars_float_STL_comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void test_spot(T val, boost::charconv::chars_format fmt = boost::charconv::chars
}

template <typename T>
void random_test(boost::charconv::chars_format fmt = boost::charconv::chars_format::general, T min_val = 0, T max_val = std::numeric_limits<T>::max())
void random_test(boost::charconv::chars_format fmt = boost::charconv::chars_format::general, T min_val = 0, T max_val = (std::numeric_limits<T>::max)())
{
std::mt19937_64 gen(42);

Expand Down Expand Up @@ -168,8 +168,8 @@ void non_finite_test(boost::charconv::chars_format fmt = boost::charconv::chars_
template <typename T>
void fixed_test()
{
constexpr T upper_bound = std::is_same<T, double>::value ? T(std::numeric_limits<std::uint64_t>::max()) :
T(std::numeric_limits<std::uint32_t>::max());
constexpr T upper_bound = std::is_same<T, double>::value ? T((std::numeric_limits<std::uint64_t>::max)()) :
T((std::numeric_limits<std::uint32_t>::max)());

std::mt19937_64 gen(42);
std::uniform_real_distribution<T> dist(1, upper_bound);
Expand Down
12 changes: 6 additions & 6 deletions test/to_chars_sprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,18 @@ template<class T> void test_sprintf_uint64()

template<class T> void test_sprintf_bv()
{
test_sprintf( std::numeric_limits<T>::min() );
test_sprintf( std::numeric_limits<T>::max() );
test_sprintf( (std::numeric_limits<T>::min)() );
test_sprintf( (std::numeric_limits<T>::max)() );
}

// floating point types, boundary values

template<class T> void test_sprintf_bv_fp()
{
test_sprintf_float( std::numeric_limits<T>::min(), boost::charconv::chars_format::scientific );
test_sprintf_float( -std::numeric_limits<T>::min(), boost::charconv::chars_format::scientific );
test_sprintf_float( std::numeric_limits<T>::max(), boost::charconv::chars_format::scientific );
test_sprintf_float( -std::numeric_limits<T>::max(), boost::charconv::chars_format::scientific );
test_sprintf_float( (std::numeric_limits<T>::min)(), boost::charconv::chars_format::scientific );
test_sprintf_float( -(std::numeric_limits<T>::min)(), boost::charconv::chars_format::scientific );
test_sprintf_float( (std::numeric_limits<T>::max)(), boost::charconv::chars_format::scientific );
test_sprintf_float( -(std::numeric_limits<T>::max)(), boost::charconv::chars_format::scientific );
}

#if BOOST_CHARCONV_LDBL_BITS > 64
Expand Down
Loading