From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3291 invoked by alias); 23 Jul 2012 10:35:56 -0000 Received: (qmail 3054 invoked by uid 22791); 23 Jul 2012 10:35:55 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W X-Spam-Check-By: sourceware.org Received: from smail3.alcatel.fr (HELO smail3.alcatel.fr) (64.208.49.56) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jul 2012 10:35:41 +0000 Received: from FRMRSSXCHHUB02.dc-m.alcatel-lucent.com (FRMRSSXCHHUB02.dc-m.alcatel-lucent.com [135.120.45.62]) by smail3.alcatel.fr (8.14.3/8.14.3/ICT) with ESMTP id q6NAZcRa017197 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Mon, 23 Jul 2012 12:35:38 +0200 Received: from [172.31.129.101] (135.120.57.7) by FRMRSSXCHHUB02.dc-m.alcatel-lucent.com (135.120.45.62) with Microsoft SMTP Server (TLS) id 8.3.213.0; Mon, 23 Jul 2012 12:35:38 +0200 Message-ID: <500D28F9.8050000@alcatel-lucent.com> Date: Mon, 23 Jul 2012 10:35:00 -0000 From: Jan Smets User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120717 Thunderbird/15.0 MIME-Version: 1.0 To: Subject: Wtype-limits and functional range checks Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-07/txt/msg00164.txt.bz2 Hi We have a lot of typicalrange checks in our code that are 'incompatible' with GCC's -Wtype-limits. (We've just upgraded from 3.4 to 4.6 and some 'type-limit' checks were enabled by default in GCC 3, but have become too noisy in GCC4) Take this example : #define MIN 0 #define MAX 100 typedef unsigned short tSomeType; int doSomething(tSomeType value) { if ((value < tSomeType_MIN) || (value > tSomeType_MAX)) { return 1; } return 0; } Would give: warning: comparison is always false due to limited range of data type [-Wtype-limits] or, if you change the typedef short to int: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits] This is 100% valid... but it's not very practical. The reason the range check is there because MIN and MAX can change flexible somewhere in the future. I'd really like to use this warning because it can improve code quality a lot. I tried to think of various ways to work around it (macro's , #pragma's) but I couldn't find any that satisfied me. Is there a way to disable this warning for "range" checks (ie, when there is both a > and < compare of the same variable) ? Can anyone help me hacking this in or at least give me some hints how to do this. (e.g, how do I know if value is used twice in the if()?) I had a look at c-family/c-common.c but I don't see how this can be done. Any help is appreciated. Thanks - Jan