From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 76648 invoked by alias); 22 Mar 2016 21:31:43 -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 76551 invoked by uid 89); 22 Mar 2016 21:31:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=permerror, Hx-languages-length:1767 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 22 Mar 2016 21:31:40 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 3C504DF203 for ; Tue, 22 Mar 2016 21:31:38 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MLVaSR020671 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 22 Mar 2016 17:31:37 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u2MLVY1Z009563; Tue, 22 Mar 2016 22:31:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u2MLVYjh009562; Tue, 22 Mar 2016 22:31:34 +0100 Date: Tue, 22 Mar 2016 21:37:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Diagnose constexpr overflow (PR c++/70323) Message-ID: <20160322213133.GP3017@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg01268.txt.bz2 Hi! On the following testcase, the first function is cp_folded into return i == 0 ? 2147483648(OVF): 2147483647; The problem is that we don't diagnose then the overflow at all. We already have code that sets *overflow_p under right conditions, just there wasn't any permerror call. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-03-22 Jakub Jelinek PR c++/70323 * constexpr.c (cxx_eval_constant_expression): Diagnose overflow on TREE_OVERFLOW constants. * g++.dg/cpp0x/constexpr-70323.C: New test. --- gcc/cp/constexpr.c.jj 2016-03-22 09:05:32.000000000 +0100 +++ gcc/cp/constexpr.c 2016-03-22 10:38:58.598077573 +0100 @@ -3306,8 +3306,13 @@ cxx_eval_constant_expression (const cons } if (CONSTANT_CLASS_P (t)) { - if (TREE_OVERFLOW (t) && (!flag_permissive || ctx->quiet)) - *overflow_p = true; + if (TREE_OVERFLOW (t)) + { + if (!ctx->quiet) + permerror (input_location, "overflow in constant expression"); + if (!flag_permissive || ctx->quiet) + *overflow_p = true; + } return t; } --- gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C.jj 2016-03-22 10:42:54.093884158 +0100 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-70323.C 2016-03-22 10:42:29.000000000 +0100 @@ -0,0 +1,10 @@ +// PR c++/70323 +// { dg-do compile { target c++11 } } + +constexpr int overflow_if_0 (int i) { return __INT_MAX__ + !i; } +constexpr int overflow_if_1 (int i) { return __INT_MAX__ + i; } + +constexpr bool i0_0 = overflow_if_0 (0); // { dg-error "overflow in constant expression" } +constexpr bool i0_1 = overflow_if_0 (1); +constexpr bool i1_0 = overflow_if_1 (0); +constexpr bool i1_1 = overflow_if_1 (1); // { dg-error "overflow in constant expression" } Jakub