C++ Templates and "comparison of unsigned expression < 0 is always false"

Jeffrey Walton noloader@gmail.com
Mon Aug 30 09:41:00 GMT 2010

Hi All,

I usually compile with -Wall -Wextra -Wno-deprecated -Wno-unused. The
options do a very good job, but I still get some noise from template

template< class T >
SomeClass<T>::SomeFunc(const T& t)
   // warning: comparison of unsigned expression < 0 is always false
   if(t < 0)

Does anyone have any tricks to remove the warning for the case that
type T is unsigned*? Or is there a "brief" switch so I can cut the
warning down to one line from the following (cryptopp/misc.h:414 and
the warning is all I really need).

cryptopp/misc.h: In function ‘std::string CryptoPP::IntToString(T,
unsigned int) [with T = long unsigned int]’:
cryptopp/simple.h:35:   instantiated from here
cryptopp/misc.h:414: warning: comparison of unsigned expression < 0 is
always false


* I don't agree with Linus and his proclamation that "GCC is crap". I
took a compiler theory class in college, and know its going to be
difficult to produce a better GCC. ("[PATCH] Don't compare unsigned
variable for <0 in sys_prctl()",

More information about the Gcc-help mailing list