From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20334 invoked by alias); 23 Sep 2013 04:04:00 -0000 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 Received: (qmail 20322 invoked by uid 89); 23 Sep 2013 04:04:00 -0000 Received: from asbnvacz-mailrelay01.megapath.net (HELO asbnvacz-mailrelay01.megapath.net) (207.145.128.243) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Sep 2013 04:04:00 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-HELO: asbnvacz-mailrelay01.megapath.net Received: from mail5.sea5.speakeasy.net (mail5.sea5.speakeasy.net [69.17.117.49]) by asbnvacz-mailrelay01.megapath.net (Postfix) with ESMTP id 74E691EE5063 for ; Mon, 23 Sep 2013 00:03:56 -0400 (EDT) Received: (qmail 26856 invoked from network); 23 Sep 2013 04:03:56 -0000 Received: by simscan 1.4.0 ppid: 18872, pid: 12250, t: 0.1575s scanners: clamav: 0.88.2/m:52/d:10739 Received: from unknown (HELO oak.schemamania.org) ([216.254.83.208]) (envelope-sender ) by mail5.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 23 Sep 2013 04:03:55 -0000 Received: from oak.schemamania.org (localhost [IPv6:::1]) by oak.schemamania.org (Postfix) with SMTP id 4033B30E118B for ; Mon, 23 Sep 2013 00:03:55 -0400 (EDT) Date: Mon, 23 Sep 2013 04:04:00 -0000 From: "James K. Lowden" To: gcc-help@gcc.gnu.org Subject: Re: how to make gcc warn about arithmetic signed overflow Message-Id: <20130923000355.fa2a964c.jklowden@schemamania.org> In-Reply-To: References: <20130921164609.GC3086@a.lan> <20130921174229.GD3086@a.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00155.txt.bz2 On Sat, 21 Sep 2013 19:30:02 +0100 Jonathan Wakely wrote: > > its value can be changed using pointers > > No, that's not true. You can't change the value of a const object in a > valid program. I don't know if we're talking C or C++ at this point, but const_cast will surely let you change the value of a const object without treading into undefined behavior. Regarding the OP's query > > int r = ab * bc; although the provided example is simple enough, it's the compiler's job is to generate object code, not to do static analysis. Even if the values are const, in the general case they could be modified by another module or another thread. The compiler simply doesn't have enough information to warn of every runtime overflow. --jkl