Skip to content

Commit

Permalink
Type which are convertible to a number should not participate in arit…
Browse files Browse the repository at this point in the history
…hmetic operator overloads.

Fixes #608
  • Loading branch information
jzmaddock committed Mar 6, 2024
1 parent 3c9ff4d commit 8f0dd78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/boost/multiprecision/detail/number_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ struct is_number_expression<detail::expression<tag, Arg1, Arg2, Arg3, Arg4> > :
template <class T, class Num>
struct is_compatible_arithmetic_type
: public std::integral_constant<bool,
std::is_convertible<T, Num>::value && !std::is_same<T, Num>::value && !is_number_expression<T>::value>
std::is_convertible<T, Num>::value && !std::is_same<T, Num>::value && !is_number_expression<T>::value
&& (std::is_constructible<typename Num::backend_type, T>::value || std::is_assignable<typename Num::backend_type, T>::value)>
{};

namespace detail {
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ test-suite misc :
[ check-target-builds ../config//has_float128 : <source>quadmath <define>TEST_FLOAT128 ]
<define>TEST_CPP_DEC_FLOAT
<define>TEST_CPP_BIN_FLOAT ]
[ compile git_issue_608.cpp ]
[ compile git_issue_98.cpp :
[ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ]
[ check-target-builds ../config//has_gmp : <define>TEST_GMP <source>gmp : ]
Expand Down
15 changes: 15 additions & 0 deletions test/git_issue_608.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright 2024 John Maddock. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <functional>
#include <boost/multiprecision/cpp_bin_float.hpp>

using big_float_type = boost::multiprecision::cpp_bin_float_100;

int main()
{
static_assert(boost::multiprecision::is_compatible_arithmetic_type<std::reference_wrapper<big_float_type>, big_float_type>::value == 0);
}

0 comments on commit 8f0dd78

Please sign in to comment.