2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Fix gcd tests and code for clang on Linux

This commit is contained in:
jzmaddock
2017-04-20 14:43:28 +01:00
parent 82e3949024
commit fafda3176c
2 changed files with 30 additions and 15 deletions

View File

@@ -49,6 +49,11 @@ namespace boost {
// some helper functions which really should be constexpr already, but sadly aren't:
//
#ifndef BOOST_NO_CXX14_CONSTEXPR
template <class T>
inline constexpr T constexpr_min(T const& a, T const& b) BOOST_GCD_NOEXCEPT(T)
{
return a < b ? a : b;
}
template <class T>
inline constexpr auto constexpr_swap(T&a, T& b) BOOST_GCD_NOEXCEPT(T) -> decltype(a.swap(b))
{
@@ -62,6 +67,11 @@ namespace boost {
b = static_cast<T&&>(t);
}
#else
template <class T>
inline T constexpr_min(T const& a, T const& b) BOOST_GCD_NOEXCEPT(T)
{
return a < b ? a : b;
}
template <class T>
inline void constexpr_swap(T&a, T& b) BOOST_GCD_NOEXCEPT(T)
{
@@ -307,7 +317,7 @@ namespace boost {
if(!v)
return u;
shifts = (std::min)(gcd_traits<T>::make_odd(u), gcd_traits<T>::make_odd(v));
shifts = constexpr_min(gcd_traits<T>::make_odd(u), gcd_traits<T>::make_odd(v));
while(gcd_traits<T>::less(1, v))
{
@@ -350,7 +360,7 @@ namespace boost {
gcd_traits<SteinDomain>::make_odd(m);
}
// m == n
m <<= (std::min)(d_m, d_n);
m <<= constexpr_min(d_m, d_n);
return m;
}

View File

@@ -617,25 +617,30 @@ void test_constexpr5()
}
#endif
#ifndef BOOST_NO_CXX11_NOEXCEPT
#if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
//
// These tests don't pass with GCC-4.x:
//
#if !defined(BOOST_GCC) || (BOOST_GCC >= 50000)
void test_noexcept()
void test_noexcept(unsigned char a, unsigned char b)
{
static_assert(noexcept(boost::math::gcd(static_cast<unsigned char>(2), static_cast<unsigned char>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned char>(a), static_cast<unsigned char>(b))), "Expected a noexcept function.");
#ifndef _MSC_VER
// This generates an internal compiler error if enabled as well as the following test:
static_assert(noexcept(boost::math::gcd(static_cast<char>(2), static_cast<char>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<char>(a), static_cast<char>(b))), "Expected a noexcept function.");
#endif
static_assert(noexcept(boost::math::gcd(static_cast<signed char>(2), static_cast<signed char>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<short>(2), static_cast<short>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned short>(2), static_cast<unsigned short>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<int>(2), static_cast<int>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned int>(2), static_cast<unsigned int>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<long>(2), static_cast<long>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned long>(2), static_cast<unsigned long>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<long long>(2), static_cast<long long>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned long long>(2), static_cast<unsigned long long>(4))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<signed char>(a), static_cast<signed char>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<short>(a), static_cast<short>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned short>(a), static_cast<unsigned short>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<int>(a), static_cast<int>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned int>(a), static_cast<unsigned int>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<long>(a), static_cast<long>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned long>(a), static_cast<unsigned long>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<long long>(a), static_cast<long long>(b))), "Expected a noexcept function.");
static_assert(noexcept(boost::math::gcd(static_cast<unsigned long long>(a), static_cast<unsigned long long>(b))), "Expected a noexcept function.");
}
#endif
#endif