From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11670 invoked by alias); 28 Mar 2012 02:21:08 -0000 Received: (qmail 11657 invoked by uid 22791); 28 Mar 2012 02:21:07 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp1.Stanford.EDU (HELO smtp.stanford.edu) (171.67.219.81) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Mar 2012 02:20:54 +0000 Received: from smtp.stanford.edu (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with SMTP id CA567420CB7 for ; Tue, 27 Mar 2012 19:20:53 -0700 (PDT) Received: from windlord.stanford.edu (windlord.Stanford.EDU [171.67.225.134]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.stanford.edu (Postfix) with ESMTPS id 9EA90420CB4 for ; Tue, 27 Mar 2012 19:20:53 -0700 (PDT) Received: by windlord.stanford.edu (Postfix, from userid 1000) id 53DBB2F4DE; Tue, 27 Mar 2012 19:20:53 -0700 (PDT) From: Russ Allbery To: gcc@gcc.gnu.org Subject: Re: Request for warnings on implicit bool to int conversions In-Reply-To: (Gabriel Dos Reis's message of "Tue, 27 Mar 2012 20:18:53 -0500") References: <97d1c137f40ae4bd6c6f89bfdbdd02ce@saf.bio.caltech.edu> <4F7261EE.4060409@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Date: Wed, 28 Mar 2012 02:21:00 -0000 Message-ID: <87398tea9n.fsf@windlord.stanford.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2012-03/txt/msg00429.txt.bz2 Gabriel Dos Reis writes: > I am trying to understand what the real issue is here. Do you want > -Wimplicit-char-to-int to? -Wimplicit-short-to-int? If not, why? > where to stop? I think it's more about conversion *to* bool than from bool, and it catches places where code has been partly converted to bool (generally because it predated C99) but the error conversion wasn't done properly. For example, while returning true or false is common, returning 0 or -1 as a boolean return value where 0 is success is also common (as with UNIX library interfaces). If someone messes up such a conversion and has a: status = -1; somewhere, they get entirely the wrong result if status becomes a bool. This warning would pick up cases like that. The warnings about doing things like: bool b = true; b++; b += 3; are somewhat akin to the warnings about doing arithmetic on void * pointers -- code like that is possibly a sign that there's something flawed with the algorithm and it should be rewritten to treat booleans as actual booleans. (For example, b++ could easily wrap, and unexpectedly fast depending on the size of bool on a platform.) -- Russ Allbery (rra@stanford.edu)