boostorg/math

Redefinition of `method_type`

Closed this issue · 8 comments

Not quite sure where this bug report should go, but here goes:

In file included from example/calculate_fourier_transform_daubechies_constants.cpp:4:
In file included from /opt/homebrew/include/boost/multiprecision/cpp_bin_float.hpp:15:
In file included from /opt/homebrew/include/boost/multiprecision/cpp_int.hpp:2367:
In file included from /opt/homebrew/include/boost/multiprecision/cpp_int/misc.hpp:29:
/opt/homebrew/include/boost/integer/common_factor_rt.hpp:105:12: fatal error: redefinition of 'method_type'
      enum method_type
           ^
./include/boost/math/tools/polynomial_gcd.hpp:45:6: note: previous definition is here
enum method_type
     ^
3 warnings and 1 error generated.
make: *** [constants] Error 1

Code to reproduce (from this PR):

#include <utility>
#include <boost/math/filters/daubechies.hpp>
#include <boost/math/tools/polynomial.hpp>
#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/math/constants/constants.hpp>

using std::pow;
using boost::multiprecision::cpp_bin_float_100;
using boost::math::filters::daubechies_scaling_filter;
using boost::math::tools::polynomial;
using boost::math::constants::half;
using boost::math::constants::root_two;

template<typename Real, size_t N>
std::vector<Real> get_constants() {
   auto h = daubechies_scaling_filter<cpp_bin_float_100, N>();
   auto p = polynomial<cpp_bin_float_100>(h.begin(), h.end());

   auto q = polynomial({half<cpp_bin_float_100>(), half<cpp_bin_float_100>()});
   q = pow(q, N);
   auto l = p/q;
   return l.data(); 
}

template<typename Real>
void print_constants(std::vector<Real> const & l) {
   std::cout << std::setprecision(std::numeric_limits<Real>::digits10 -10);
   std::cout << "return std::array<Real, " << l.size() << ">{";
   for (size_t i = 0; i < l.size() - 1; ++i) {
       std::cout << "BOOST_MATH_BIG_CONSTANT(Real, std::numeric_limits<Real>::digits, " << l[i]/root_two<Real>() << "), ";
   }
   std::cout << "BOOST_MATH_BIG_CONSTANT(Real, std::numeric_limits<Real>::digits, " << l.back()/root_two<Real>() << ")};\n";
}

int main() {
   auto constants = get_constants<cpp_bin_float_100, 1>();
   print_constants(constants);
}

I note that is we remove the multiprecision code and compile in double precision, the error goes away.

Are you building with the math standalone but the full multi-precision?

@mborland : Yeah . . . undef'ing BOOST_MATH_STANDALONE fixed it. I think this one is on me . . .

Should I add guardrails where if one standalone is defined it automatically defines the other one?

@mborland : I'm not sure . . . I was only using the -DBOOST_MATH_STANDALONE to get rid of the snprintf warning from multiprecision, so I doubt this is something of huge relevance going forward.

Is the sprintf message actually coming from Multiprecision or another library? I've had the fix merged in a ton of places.

Well it's because I'm consuming the rest of boost via homebrew:

In file included from ./include/boost/math/tools/convert_from_string.hpp:15:
In file included from /opt/homebrew/include/boost/lexical_cast.hpp:32:
In file included from /opt/homebrew/include/boost/lexical_cast/try_lexical_convert.hpp:44:
In file included from /opt/homebrew/include/boost/lexical_cast/detail/converter_lexical.hpp:54:
/opt/homebrew/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:310:21: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
                    sprintf(begin,
                    ^

I think you do have it fixed on develop.

That one is fixed for 1.82

Closing as this appears to be fixed.