From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13284 invoked by alias); 21 Sep 2013 17:36:47 -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 13275 invoked by uid 89); 21 Sep 2013 17:36:47 -0000 Received: from mdfmta005.mxout.tbr.inty.net (HELO smtp.demon.co.uk) (91.221.168.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sat, 21 Sep 2013 17:36:47 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,HELO_MISC_IP,RDNS_NONE autolearn=no version=3.3.2 X-HELO: smtp.demon.co.uk Received: from mdfmta005.tbr.inty.net (unknown [127.0.0.1]) by mdfmta005.tbr.inty.net (Postfix) with ESMTP id 6693DA644E7 for ; Sat, 21 Sep 2013 18:36:43 +0100 (BST) Received: from mdfmta005.tbr.inty.net (unknown [127.0.0.1]) by mdfmta005.tbr.inty.net (Postfix) with ESMTP id 2E69DA64401 for ; Sat, 21 Sep 2013 18:36:43 +0100 (BST) Received: from [192.168.254.1] (unknown [62.49.20.82]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mdfmta005.tbr.inty.net (Postfix) with ESMTP for ; Sat, 21 Sep 2013 18:36:42 +0100 (BST) Message-ID: <1379785029.2477.8.camel@Gannet.Four> Subject: Re: how to make gcc warn about arithmetic signed overflow From: Brian Drummond Reply-To: brian@shapes.demon.co.uk To: gcc-help@gcc.gnu.org Date: Sat, 21 Sep 2013 17:36:00 -0000 In-Reply-To: <20130921164609.GC3086@a.lan> References: <20130921164609.GC3086@a.lan> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-MDF-HostID: 8 X-IsSubscribed: yes X-SW-Source: 2013-09/txt/msg00135.txt.bz2 On Sat, 2013-09-21 at 18:46 +0200, wempwer@gmail.com wrote: > int ab = 50000; > int bc = 50000; > int r = ab * bc; > > Is it possible for gcc to produce a > warning in such situation? Yes, gcc the Gnu Compiler Collection can produce such a warning: procedure test_ovf is ab : integer := 50000; bc : integer := 50000; r : integer := ab * bc; begin null; end test_ovf; gcc -c test_ovf.adb test_ovf.adb:4:22: warning: value not in range of type "Standard.Integer" test_ovf.adb:4:22: warning: "Constraint_Error" will be raised at run time However I'm not sure it is allowed to do the same with C. - Brian