From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10646 invoked by alias); 7 May 2010 07:14:09 -0000 Received: (qmail 10562 invoked by uid 48); 7 May 2010 07:13:52 -0000 Date: Fri, 07 May 2010 07:14:00 -0000 Subject: [Bug c++/44021] New: Templates with -Wtype-limits produces warnings. X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "crossroads0000 at googlemail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-05/txt/msg00660.txt.bz2 -Wtype-limits should not produce warnings in the following example: template 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(3); foo(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