From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53386 invoked by alias); 27 Sep 2016 13:34:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 53370 invoked by uid 89); 27 Sep 2016 13:34:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=ciao, Hx-languages-length:991 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Sep 2016 13:34:00 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 53FA3ABA5; Tue, 27 Sep 2016 13:33:58 +0000 (UTC) Date: Tue, 27 Sep 2016 13:48:00 -0000 From: Michael Matz To: Jason Merrill cc: Bernd Edlinger , "gcc-patches@gcc.gnu.org" , Jeff Law Subject: Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg01983.txt.bz2 Hi, On Tue, 27 Sep 2016, Jason Merrill wrote: > On Sun, Sep 25, 2016 at 3:46 AM, Bernd Edlinger > wrote: > > This patch makes -Wint-in-bool-context warn on suspicious integer left > > shifts, when the integer is signed, which is most likely some kind of > > programming error, for instance using "<<" instead of "<". > > > > The warning is motivated by the fact, that an overflow on integer shift > > left is undefined behavior, even if gcc won't optimize the shift based > > on the undefined behavior. > > > > So in absence of undefined behavior the boolean result does not depend > > on the shift value, thus the whole shifting is pointless. > > It's pointless for unsigned integers, too; why not warn for them as > well? Um, because left shift on unsigned integers is never undefined, so !!(1u << a) is meaningful and effectively tests if a < CHAR_BITS*sizeof(unsigned) ? Ciao, Michael.