-Wtype-limits should not produce warnings in the following example: template<class integer> bool foo(integer x) { if(x >= 0) { // Do something here if integer is positive. return false; } else if(x < 0) // Used else if() here instead of just else to get 2nd warning. { // Do something else here if integer is negative. return true; } }
int main() { foo<unsigned int>(3); foo<int>(3); return 0; } The first line in the main() function, together with -Wtype-limits (or -Wextra), produces these warnings: warning: comparison of unsigned expression >= 0 is always true warning: comparison of unsigned expression < 0 is always false While these warnings makes sense for all other cases, they should not occur for comparison of template types, since it does not easily allow for warning-free templates which can handle unsigned and signed integers and have different behavior for negative numbers. Disabling the warning with -Wno-type-limits works as a temporary solution, but this also makes finding potential bugs in non-template code more difficult. Regards, Jason. -- Summary: Templates with -Wtype-limits produces warnings. Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: crossroads0000 at googlemail dot com GCC build triplet: x86_64-linux-elf GCC host triplet: x86_64-linux-elf GCC target triplet: x86_64-linux-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44021