From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59920 invoked by alias); 12 Jan 2016 14:16:13 -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 59857 invoked by uid 89); 12 Jan 2016 14:16:12 -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,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=positions 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, 12 Jan 2016 14:16:03 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id AE70E19EF1D for ; Tue, 12 Jan 2016 14:16:01 +0000 (UTC) Received: from redhat.com (ovpn-204-42.brq.redhat.com [10.40.204.42]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0CEFwBn015597 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 12 Jan 2016 09:16:00 -0500 Date: Tue, 12 Jan 2016 14:16:00 -0000 From: Marek Polacek To: Jason Merrill Cc: GCC Patches Subject: Re: C++ PATCH to abate shift warnings (PR c++/68979) Message-ID: <20160112141557.GH25528@redhat.com> References: <20160112125201.GE25528@redhat.com> <5694FF53.1060305@redhat.com> <20160112140552.GG25528@redhat.com> <56950922.1020607@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56950922.1020607@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2016-01/txt/msg00730.txt.bz2 On Tue, Jan 12, 2016 at 09:09:38AM -0500, Jason Merrill wrote: > In that case, we need to return (!flag_permissive || ctx->quiet). Thanks. So is this one ok once it passes testing? Bootstrapped/regtested on x86_64-linux, ok for trunk? 2016-01-12 Marek Polacek PR c++/68979 * constexpr.c (cxx_eval_check_shift_p): Use permerror rather than error_at and adjust the return value. * g++.dg/warn/permissive-1.C: New test. diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index e60180e..36a1e42 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -1512,17 +1512,17 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx, if (tree_int_cst_sgn (rhs) == -1) { if (!ctx->quiet) - error_at (loc, "right operand of shift expression %q+E is negative", - build2_loc (loc, code, type, lhs, rhs)); - return true; + permerror (loc, "right operand of shift expression %q+E is negative", + build2_loc (loc, code, type, lhs, rhs)); + return (!flag_permissive || ctx->quiet); } if (compare_tree_int (rhs, uprec) >= 0) { if (!ctx->quiet) - error_at (loc, "right operand of shift expression %q+E is >= than " - "the precision of the left operand", - build2_loc (loc, code, type, lhs, rhs)); - return true; + permerror (loc, "right operand of shift expression %q+E is >= than " + "the precision of the left operand", + build2_loc (loc, code, type, lhs, rhs)); + return (!flag_permissive || ctx->quiet); } /* The value of E1 << E2 is E1 left-shifted E2 bit positions; [...] @@ -1536,9 +1536,10 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx, if (tree_int_cst_sgn (lhs) == -1) { if (!ctx->quiet) - error_at (loc, "left operand of shift expression %q+E is negative", - build2_loc (loc, code, type, lhs, rhs)); - return true; + permerror (loc, + "left operand of shift expression %q+E is negative", + build2_loc (loc, code, type, lhs, rhs)); + return (!flag_permissive || ctx->quiet); } /* For signed x << y the following: (unsigned) x >> ((prec (lhs) - 1) - y) @@ -1555,9 +1556,9 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx, if (tree_int_cst_lt (integer_one_node, t)) { if (!ctx->quiet) - error_at (loc, "shift expression %q+E overflows", - build2_loc (loc, code, type, lhs, rhs)); - return true; + permerror (loc, "shift expression %q+E overflows", + build2_loc (loc, code, type, lhs, rhs)); + return (!flag_permissive || ctx->quiet); } } return false; diff --git gcc/testsuite/g++.dg/warn/permissive-1.C gcc/testsuite/g++.dg/warn/permissive-1.C index e69de29..bfaca76 100644 --- gcc/testsuite/g++.dg/warn/permissive-1.C +++ gcc/testsuite/g++.dg/warn/permissive-1.C @@ -0,0 +1,8 @@ +// PR c++/68979 +// { dg-do compile { target int32 } } +// { dg-options "-fpermissive -Wno-shift-overflow -Wno-shift-count-overflow -Wno-shift-count-negative" } + +enum A { AA = -1 << 4 }; // { dg-warning "operand of shift expression" "" { target c++11 } } +enum B { BB = 1 << -4 }; // { dg-warning "operand of shift expression" } +enum C { CC = 1 << __SIZEOF_INT__ * 4 * __CHAR_BIT__ - 4 }; // { dg-warning "operand of shift expression" } +enum D { DD = 10 << __SIZEOF_INT__ * __CHAR_BIT__ - 2 }; // { dg-warning "shift expression" "" { target c++11 } } Marek