[type_traits] warning free is_signed on g++

Hello, When using boost::is_signed<> on types such as unsigned int and unsigned long, various recent versions of g++ (MinGW 4.4.0 and Apple's 4.0.1, at least) spit out a warning: warning: comparison of unsigned expression < 0 is always false Would there be any harm in changing boost::detail::is_signed_helper in boost/type_traits/is_signed.hpp as follows? template <class T> struct is_signed_helper { typedef typename remove_cv<T>::type no_cv_t; // BOOST_STATIC_CONSTANT(bool, value = (static_cast<no_cv_t>(-1) < 0)); BOOST_STATIC_CONSTANT(bool, value = (static_cast<no_cv_t>(-1) < 1)); }; This change gets rid of the warnings emitted by g++. Kind regards, Edd

On Sat, Sep 12, 2009 at 10:51 AM, Edd Dawson <lists@mr-edd.co.uk> wrote:
Hello,
When using boost::is_signed<> on types such as unsigned int and unsigned long, various recent versions of g++ (MinGW 4.4.0 and Apple's 4.0.1, at least) spit out a warning:
warning: comparison of unsigned expression < 0 is always false
Would there be any harm in changing boost::detail::is_signed_helper in boost/type_traits/is_signed.hpp as follows?
template <class T> struct is_signed_helper { typedef typename remove_cv<T>::type no_cv_t; // BOOST_STATIC_CONSTANT(bool, value = (static_cast<no_cv_t>(-1) < 0)); BOOST_STATIC_CONSTANT(bool, value = (static_cast<no_cv_t>(-1) < 1)); };
Is it possible for T to be a (strangely) user-defined type? That's the only way I could see this making a difference. Tony

When using boost::is_signed<> on types such as unsigned int and unsigned long, various recent versions of g++ (MinGW 4.4.0 and Apple's 4.0.1, at least) spit out a warning:
warning: comparison of unsigned expression < 0 is always false
Would there be any harm in changing boost::detail::is_signed_helper in boost/type_traits/is_signed.hpp as follows?
template <class T> struct is_signed_helper { typedef typename remove_cv<T>::type no_cv_t; // BOOST_STATIC_CONSTANT(bool, value = (static_cast<no_cv_t>(-1) < 0)); BOOST_STATIC_CONSTANT(bool, value = (static_cast<no_cv_t>(-1) < 1)); };
This change gets rid of the warnings emitted by g++.
Already been there and fixed it: https://svn.boost.org/trac/boost/ticket/3381 John.
participants (3)
-
Edd Dawson
-
Gottlob Frege
-
John Maddock