Aliesha Finkel <[EMAIL PROTECTED]> writes: > | Hi, I'm using -Wextra (-W) to compile my code, one > | feature of which is throwing a warning when an > | unsigned type is checked for >= 0 since it's always > | true. In general I find this to be very helpful, but > | it throws this error even for templated types... > | > | template <typename T> > | struct foo { > | foo(T bar) { if (bar >= 0) bar = 1; } > | };
On Wed, May 10, 2006 at 01:38:29PM +0200, Gabriel Dos Reis wrote: > This is an issue as well for gcjx -- it can be annoying. I think that the warning is useful if the comparison is *always* true for any call of foo<anything>. But here, whether the test is redundant or not depends on the type of bar. Possibly there's a way to determine that the type of bar is a template argument and suppress the warning in that case. But then I just thought of another case: template <typename Container> struct foo { foo(const Container& bar) { if (bar.size() >= 0) use(bar); } }; For any STL-compliant container the test is redundant. But if we put in a rule saying to suppress the warning if the type depends on a template, we lose the warning in this case as well; after all, nothing stops someone from writing class C { public: int size() const; ... }; void use(const C&);