This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13553] New: ADL failure in Boost.Math library


I have a strange case where a using declaration prevents Argument-Dependent-
Lookup from working correctly, the test code below is abstracted from the 
Boost.Math library, and works as expected with VC++7.1, Metrowerks, and recent 
EDG based compilers (EDG 3.1.1 frontend), but fails with gcc 3.3.1:

#include <cmath>
#include <cstdlib>

namespace boost{ namespace math{

template<typename T, template<typename> class U>
U<T> test(const U<T>& t)
{
  using std::abs;
  return abs(t);
}


template <class T>
struct numeric
{
  numeric(){ m_value = 0; }
  explicit numeric(T t){ m_value = t; }
  T value()const { return m_value; }
  private:
  T m_value;
};

template <class T>
numeric<T> operator+(const numeric<T>& a, const numeric<T>& b)
{
  return numeric<T>(a.value() + b.value());
}

template <class T>
numeric<T> abs(const numeric<T>& a)
{
  using std::abs;
  return numeric<T>(abs(a.value()));
}

}

}

int main()
{
   boost::math::numeric<double> num(2);
   boost::math::test(num);
   return 0;
}

There is a workaround, which is to replace the
 
using std::abs; 

with 

using namespace std;

However that is a rather brutal workaround, which may have unfortunate side 
effects.

Thanks,

John Maddock

-- 
           Summary: ADL failure in Boost.Math library
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: john at johnmaddock dot co dot uk
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13553


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]