|
Boost Users : |
Subject: Re: [Boost-users] Boost 1.42 TR1 With GCC 4.5 selects wrong overload
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-01-13 08:20:54
>I am using the portable style boost headers for tr1 implementation from
> Boost 1.42 such as #include <boost/tr1/type_traits.hpp>
>
> When i use gcc implementation of tr1 (Mingw GCC 4.5.1 from TDM,
> BOOST_HAS_GCC_TR1 defined) everything works fine.
> However when i select boost tr1 implementation (i.e not define the above
> macro) some stdlib functions such as std::abs gets
> wrong overloaded selected. For. e.g. in gcc/tr1 std::abs((signed char)5)
> returns an int while in boost/tr1 it returns a double.
>
> A compilable example is like
> #include <cstdlib>
> #include <iostream>
> #include <typeinfo>
> #include <boost/tr1/type_traits.hpp>
> int main(){
> std::cout<<typeid(std::abs((short)5)).name();
> //prints i with gcc/tr1 while prints d with boost/tr1
> }
>
> it happens with type_traits header (may be few other also) but not with
> all
> tr1 headers(such as array).
It's nothing to do with us, some TR1 headers just so happen to include
<cmath> and in gcc-4.5 there is an abs overload that looks like:
template<typename _Tp>
inline typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
double>::__type
abs(_Tp __x)
{ return __builtin_fabs(__x); }
Which gets selected for all integer arguments other than int/long/long long.
Whether this is C++0x conforming behavior though I'm not sure...
HTH, John.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net