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

Fixes for -Wzero-as-null-pointer-constant #798

Merged
merged 6 commits into from
Jul 11, 2022
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/math/bindings/mpfr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ mpfr_class digamma_imp(mpfr_class x, const std::integral_constant<int, 0>* , con
//
if(remainder == 0)
{
return policies::raise_pole_error<mpfr_class>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
return policies::raise_pole_error<mpfr_class>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
}
result = constants::pi<mpfr_class>() / tan(constants::pi<mpfr_class>() * remainder);
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/bindings/mpreal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ mpfr::mpreal digamma_imp(mpfr::mpreal x, const std::integral_constant<int, 0>* ,
//
if(remainder == 0)
{
return policies::raise_pole_error<mpfr::mpreal>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
return policies::raise_pole_error<mpfr::mpreal>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
}
result = constants::pi<mpfr::mpreal>() / tan(constants::pi<mpfr::mpreal>() * remainder);
}
Expand Down
18 changes: 9 additions & 9 deletions include/boost/math/bindings/rr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class RR
int exp = 0;
NTL::RR t;
bool neg = a < V(0) ? true : false;
if(neg)
if(neg)
a = -a;
while(a)
{
Expand Down Expand Up @@ -467,7 +467,7 @@ struct ntl_lanczos
return lanczos61UDT::lanczos_sum_near_2(z);
}
static ntl::RR g()
{
{
unsigned long p = ntl::RR::precision();
if(p <= 72)
return lanczos13UDT::g();
Expand Down Expand Up @@ -691,8 +691,8 @@ namespace ntl{
double r;
conv(r, z.value());
return boost::math::tools::halley_iterate(
asin_root(z),
RR(std::asin(r)),
asin_root(z),
RR(std::asin(r)),
RR(-boost::math::constants::pi<RR>()/2),
RR(boost::math::constants::pi<RR>()/2),
NTL::RR::precision());
Expand All @@ -719,8 +719,8 @@ namespace ntl{
double r;
conv(r, z.value());
return boost::math::tools::halley_iterate(
acos_root(z),
RR(std::acos(r)),
acos_root(z),
RR(std::acos(r)),
RR(-boost::math::constants::pi<RR>()/2),
RR(boost::math::constants::pi<RR>()/2),
NTL::RR::precision());
Expand Down Expand Up @@ -748,8 +748,8 @@ namespace ntl{
double r;
conv(r, z.value());
return boost::math::tools::halley_iterate(
atan_root(z),
RR(std::atan(r)),
atan_root(z),
RR(std::atan(r)),
-boost::math::constants::pi<RR>()/2,
boost::math::constants::pi<RR>()/2,
NTL::RR::precision());
Expand Down Expand Up @@ -858,7 +858,7 @@ ntl::RR digamma_imp(ntl::RR x, const std::integral_constant<int, 0>* , const Pol
//
if(remainder == 0)
{
return policies::raise_pole_error<ntl::RR>("boost::math::digamma<%1%>(%1%)", 0, (1-x), pol);
return policies::raise_pole_error<ntl::RR>("boost::math::digamma<%1%>(%1%)", nullptr, (1-x), pol);
}
result = constants::pi<ntl::RR>() / tan(constants::pi<ntl::RR>() * remainder);
}
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/concepts/distributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class distribution_archetype
static distribution_archetype& get_object()
{
// will never get caled:
return *reinterpret_cast<distribution_archetype*>(0);
return *reinterpret_cast<distribution_archetype*>(nullptr);
}
}; // template <class RealType>class distribution_archetype

Expand Down
4 changes: 2 additions & 2 deletions include/boost/math/distributions/beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ namespace boost
{
return 1;
}
return ibeta_inv(a, b, p, static_cast<RealType*>(0), Policy());
return ibeta_inv(a, b, p, static_cast<RealType*>(nullptr), Policy());
} // quantile

template <class RealType, class Policy>
Expand Down Expand Up @@ -535,7 +535,7 @@ namespace boost
return 1;
}

return ibetac_inv(a, b, q, static_cast<RealType*>(0), Policy());
return ibetac_inv(a, b, q, static_cast<RealType*>(nullptr), Policy());
} // Quantile Complement

} // namespace math
Expand Down
8 changes: 4 additions & 4 deletions include/boost/math/distributions/binomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ namespace boost
// NOTE!!! The Clopper Pearson formula uses "successes" not
// "successes+1" as usual to get the lower bound,
// see http://www.itl.nist.gov/div898/handbook/prc/section2/prc241.htm
return (t == clopper_pearson_exact_interval) ? ibeta_inv(successes, trials - successes + 1, probability, static_cast<RealType*>(0), Policy())
: ibeta_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy());
return (t == clopper_pearson_exact_interval) ? ibeta_inv(successes, trials - successes + 1, probability, static_cast<RealType*>(nullptr), Policy())
: ibeta_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(nullptr), Policy());
}
static RealType find_upper_bound_on_p(
RealType trials,
Expand All @@ -357,8 +357,8 @@ namespace boost
if(trials == successes)
return 1;

return (t == clopper_pearson_exact_interval) ? ibetac_inv(successes + 1, trials - successes, probability, static_cast<RealType*>(0), Policy())
: ibetac_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(0), Policy());
return (t == clopper_pearson_exact_interval) ? ibetac_inv(successes + 1, trials - successes, probability, static_cast<RealType*>(nullptr), Policy())
: ibetac_inv(successes + 0.5f, trials - successes + 0.5f, probability, static_cast<RealType*>(nullptr), Policy());
}
// Estimate number of trials parameter:
//
Expand Down
4 changes: 2 additions & 2 deletions include/boost/math/distributions/detail/derived_accessors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline typename Distribution::value_type hazard(const Distribution& dist, const
value_type d = pdf(dist, x);
if(d > p * tools::max_value<value_type>())
return policies::raise_overflow_error<value_type>(
"boost::math::hazard(const Distribution&, %1%)", 0, policy_type());
"boost::math::hazard(const Distribution&, %1%)", nullptr, policy_type());
if(d == 0)
{
// This protects against 0/0, but is it the right thing to do?
Expand Down Expand Up @@ -94,7 +94,7 @@ inline typename Distribution::value_type coefficient_of_variation(const Distribu
value_type d = standard_deviation(dist);
if((abs(m) < 1) && (d > abs(m) * tools::max_value<value_type>()))
{ // Checks too that m is not zero,
return policies::raise_overflow_error<value_type>("boost::math::coefficient_of_variation(const Distribution&, %1%)", 0, policy_type());
return policies::raise_overflow_error<value_type>("boost::math::coefficient_of_variation(const Distribution&, %1%)", nullptr, policy_type());
}
return d / m; // so MSVC warning on zerodivide is spurious, and suppressed.
}
Expand Down
32 changes: 19 additions & 13 deletions include/boost/math/distributions/detail/generic_quantile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace boost{ namespace math{ namespace detail{
template <class Dist>
struct generic_quantile_finder
{
typedef typename Dist::value_type value_type;
typedef typename Dist::policy_type policy_type;
using value_type = typename Dist::value_type;
using policy_type = typename Dist::policy_type;

generic_quantile_finder(const Dist& d, value_type t, bool c)
: dist(d), target(t), comp(c) {}
Expand All @@ -34,25 +34,31 @@ template <class T, class Policy>
inline T check_range_result(const T& x, const Policy& pol, const char* function)
{
if((x >= 0) && (x < tools::min_value<T>()))
return policies::raise_underflow_error<T>(function, 0, pol);
{
return policies::raise_underflow_error<T>(function, nullptr, pol);
}
if(x <= -tools::max_value<T>())
return -policies::raise_overflow_error<T>(function, 0, pol);
{
return -policies::raise_overflow_error<T>(function, nullptr, pol);
}
if(x >= tools::max_value<T>())
return policies::raise_overflow_error<T>(function, 0, pol);
{
return policies::raise_overflow_error<T>(function, nullptr, pol);
}
return x;
}

template <class Dist>
typename Dist::value_type generic_quantile(const Dist& dist, const typename Dist::value_type& p, const typename Dist::value_type& guess, bool comp, const char* function)
{
typedef typename Dist::value_type value_type;
typedef typename Dist::policy_type policy_type;
typedef typename policies::normalise<
policy_type,
policies::promote_float<false>,
policies::promote_double<false>,
policies::discrete_quantile<>,
policies::assert_undefined<> >::type forwarding_policy;
using value_type = typename Dist::value_type;
using policy_type = typename Dist::policy_type;
using forwarding_policy = typename policies::normalise<
policy_type,
policies::promote_float<false>,
policies::promote_double<false>,
policies::discrete_quantile<>,
policies::assert_undefined<> >::type;

//
// Special cases first:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class empirical_cumulative_distribution_function {
if constexpr (std::is_integral_v<Real>)
{
if (x < m_v[0]) {
return double(0);
return static_cast<double>(0);
}
if (x >= m_v[m_v.size()-1]) {
return double(1);
return static_cast<double>(1);
}
auto it = std::upper_bound(m_v.begin(), m_v.end(), x);
return static_cast<double>(std::distance(m_v.begin(), it))/static_cast<double>(m_v.size());
Expand Down
10 changes: 5 additions & 5 deletions include/boost/math/distributions/geometric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace boost
// Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY
// http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf
//
return ibeta_inv(successes, failures + 1, alpha, static_cast<RealType*>(0), Policy());
return ibeta_inv(successes, failures + 1, alpha, static_cast<RealType*>(nullptr), Policy());
} // find_lower_bound_on_p

static RealType find_upper_bound_on_p(
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace boost
// Discrete Distributions" Yong CAI and K. Krishnamoorthy
// http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf
//
return ibetac_inv(successes, failures, alpha, static_cast<RealType*>(0), Policy());
return ibetac_inv(successes, failures, alpha, static_cast<RealType*>(nullptr), Policy());
} // find_upper_bound_on_p

// Estimate number of trials :
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace boost
if(false == geometric_detail::check_dist_and_k(
function, p, k, &result, Policy())
&& detail::check_probability(function, alpha, &result, Policy()))
{
{
return result;
}
result = ibetac_inva(k + 1, p, alpha, Policy()); // returns n - k
Expand Down Expand Up @@ -270,7 +270,7 @@ namespace boost
BOOST_MATH_STD_USING // ADL of std functions.
return 0;
} // mode

template <class RealType, class Policy>
inline RealType variance(const geometric_distribution<RealType, Policy>& dist)
{ // Variance of Binomial distribution = (1-p) / p^2.
Expand Down Expand Up @@ -446,7 +446,7 @@ namespace boost
{
return 0;
}

// log(1-x) /log(1-success_fraction) -1; but use log1p in case success_fraction is small
result = boost::math::log1p(-x, Policy()) / boost::math::log1p(-success_fraction, Policy()) - 1;
// Subtract a few epsilons here too?
Expand Down
4 changes: 2 additions & 2 deletions include/boost/math/distributions/negative_binomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace boost
// Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY
// http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf
//
return ibeta_inv(successes, failures + 1, alpha, static_cast<RealType*>(0), Policy());
return ibeta_inv(successes, failures + 1, alpha, static_cast<RealType*>(nullptr), Policy());
} // find_lower_bound_on_p

static RealType find_upper_bound_on_p(
Expand Down Expand Up @@ -204,7 +204,7 @@ namespace boost
// Discrete Distributions" Yong CAI and K. KRISHNAMOORTHY
// http://www.ucs.louisiana.edu/~kxk4695/Discrete_new.pdf
//
return ibetac_inv(successes, failures, alpha, static_cast<RealType*>(0), Policy());
return ibetac_inv(successes, failures, alpha, static_cast<RealType*>(nullptr), Policy());
} // find_upper_bound_on_p

// Estimate number of trials :
Expand Down
38 changes: 23 additions & 15 deletions include/boost/math/policies/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
namespace boost{ namespace math{

#ifndef BOOST_NO_EXCEPTIONS

class evaluation_error : public std::runtime_error
{
public:
evaluation_error(const std::string& s) : std::runtime_error(s){}
explicit evaluation_error(const std::string& s) : std::runtime_error(s){}
};

class rounding_error : public std::runtime_error
{
public:
rounding_error(const std::string& s) : std::runtime_error(s){}
explicit rounding_error(const std::string& s) : std::runtime_error(s){}
};

#endif
Expand Down Expand Up @@ -132,10 +132,14 @@ inline const char* name_of<BOOST_MATH_FLOAT128_TYPE>()
template <class E, class T>
void raise_error(const char* pfunction, const char* message)
{
if(pfunction == 0)
if(pfunction == nullptr)
{
pfunction = "Unknown function operating on type %1%";
if(message == 0)
}
if(message == nullptr)
{
message = "Cause unknown";
}

std::string function(pfunction);
std::string msg("Error in function ");
Expand All @@ -155,10 +159,14 @@ void raise_error(const char* pfunction, const char* message)
template <class E, class T>
void raise_error(const char* pfunction, const char* pmessage, const T& val)
{
if(pfunction == 0)
if(pfunction == nullptr)
{
pfunction = "Unknown function operating on type %1%";
if(pmessage == 0)
}
if(pmessage == nullptr)
{
pmessage = "Cause unknown: error caused by bad argument with value %1%";
}

std::string function(pfunction);
std::string message(pmessage);
Expand Down Expand Up @@ -748,7 +756,7 @@ inline bool check_overflow(T val, R* result, const char* function, const Policy&
BOOST_MATH_STD_USING
if(fabs(val) > tools::max_value<R>())
{
boost::math::policies::detail::raise_overflow_error<R>(function, 0, pol);
boost::math::policies::detail::raise_overflow_error<R>(function, nullptr, pol);
*result = static_cast<R>(val);
return true;
}
Expand All @@ -769,7 +777,7 @@ inline bool check_underflow(T val, R* result, const char* function, const Policy
{
if((val != 0) && (static_cast<R>(val) == 0))
{
*result = static_cast<R>(boost::math::policies::detail::raise_underflow_error<R>(function, 0, pol));
*result = static_cast<R>(boost::math::policies::detail::raise_underflow_error<R>(function, nullptr, pol));
return true;
}
return false;
Expand Down Expand Up @@ -808,22 +816,22 @@ inline bool check_denorm(std::complex<T> val, R* result, const char* function, c

// Default instantiations with ignore_error policy.
template <class R, class T>
inline constexpr bool check_overflow(T /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
inline constexpr bool check_overflow(T /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
{ return false; }
template <class R, class T>
inline constexpr bool check_overflow(std::complex<T> /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
inline constexpr bool check_overflow(std::complex<T> /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
{ return false; }
template <class R, class T>
inline constexpr bool check_underflow(T /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
inline constexpr bool check_underflow(T /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
{ return false; }
template <class R, class T>
inline constexpr bool check_underflow(std::complex<T> /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
inline constexpr bool check_underflow(std::complex<T> /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
{ return false; }
template <class R, class T>
inline constexpr bool check_denorm(T /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
inline constexpr bool check_denorm(T /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
{ return false; }
template <class R, class T>
inline constexpr bool check_denorm(std::complex<T> /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
inline constexpr bool check_denorm(std::complex<T> /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&) noexcept(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T))
{ return false; }

} // namespace detail
Expand Down
Loading