Skip to content

Commits on Source 1

  • Tyler Veness's avatar
    Fix ambiguous sqrt() overload caused by ADL · be56fff1
    Tyler Veness authored and Charles Schlosser's avatar Charles Schlosser committed
    Here's the compiler error:
    ```
    /home/tav/git/Sleipnir/build/_deps/eigen3-src/Eigen/src/Householder/Householder.h:82:16: error: call of overloaded ‘sqrt(boost::decimal::decimal64_t)’ is ambiguous
       82 |     beta = sqrt(numext::abs2(c0) + tailSqNorm);
          |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /home/tav/git/Sleipnir/build/_deps/eigen3-src/Eigen/src/Householder/Householder.h:82:16: note: there are 2 candidates
    In file included from /home/tav/git/Sleipnir/build/_deps/eigen3-src/Eigen/Core:198,
                     from /home/tav/git/Sleipnir/test/src/optimization/cart_pole_problem_test.cpp:8:
    /home/tav/git/Sleipnir/build/_deps/eigen3-src/Eigen/src/Core/MathFunctions.h:1384:75: note: candidate 1: ‘typename Eigen::internal::sqrt_retval<typename Eigen::internal::global_math_functions_filtering_base<Scalar>::type>::type Eigen::numext::sqrt(const Scalar&) [with Scalar = boost::decimal::decimal64_t; typename Eigen::internal::sqrt_retval<typename Eigen::internal::global_math_functions_filtering_base<Scalar>::type>::type = boost::decimal::decimal64_t; typename Eigen::internal::global_math_functions_filtering_base<Scalar>::type = boost::decimal::decimal64_t]’
     1384 | EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(const Scalar& x) {
          |                                                                           ^~~~
    In file included from /home/tav/git/Sleipnir/build/_deps/decimal-src/include/boost/decimal/detail/cmath/ellint_1.hpp:16,
                     from /home/tav/git/Sleipnir/build/_deps/decimal-src/include/boost/decimal/cmath.hpp:18,
                     from /home/tav/git/Sleipnir/build/_deps/decimal-src/include/boost/decimal.hpp:33,
                     from /home/tav/git/Sleipnir/test/include/scalar_types_under_test.hpp:6,
                     from /home/tav/git/Sleipnir/test/src/optimization/cart_pole_problem_test.cpp:19:
    /home/tav/git/Sleipnir/build/_deps/decimal-src/include/boost/decimal/detail/cmath/sqrt.hpp:167:16: note: candidate 2: ‘constexpr T boost::decimal::sqrt(T) requires  is_decimal_floating_point_v<T> [with T = decimal64_t]’
      167 | constexpr auto sqrt(const T val) noexcept
          |                ^~~~
    ```
    
    Calling a function via its unqualified name invokes argument-dependent lookup. In this case, since `using numext::sqrt;` was used, both `numext::sqrt()` and `boost::decimal::sqrt()` participated in overload resolution. Since only `numext::sqrt()` was intended, the fix is to call that overload directly instead.
    
    See merge request !2044
    be56fff1
Loading