From patchwork Tue Oct 18 20:26:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 683866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sz67W0wlnz9s2Q for ; Wed, 19 Oct 2016 07:27:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=W5JqsAzC; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=rXDnA8LT8GP1VENNg lX23DyHBqRlqP2GehTZ0VmQ3EFAub46mJSvac59wGVmFsgk9+3SG+XTfOpT0GYm5 FbHuXtQxt54JceLxn1/Ry4eIBTAhDzl7dcZJVgtHtbTxcAYMU8Ds8J55PMguMk+b RhSP+ialpGTh1PvtJMIOJeSVkI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=64y4i8qISgMv1hpEnjTLa61 j9Sw=; b=W5JqsAzC3DByX4aEw8I0lrkGEUSekdgajuKbKkuqU1mu7TG1J/ilKxA sYNFWsQkA46ft3XFdGButLEfqBq/mSRids1r5lTxfMfi7Z3yRisZ+/Dq3FKGjRHc /ulajxsMxWO4fxRT05xeWn+8cIlRftHze0iL+91zlPZ5o8zNn6I4= Received: (qmail 110806 invoked by alias); 18 Oct 2016 20:27:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 110795 invoked by uid 89); 18 Oct 2016 20:27:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=BAYES_50, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=no version=3.3.2 spammy=recur, RECUR, sk:cpp14_c, sk:c_inhib X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Oct 2016 20:27:00 +0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u9IKQwBm031397 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Oct 2016 20:26:58 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u9IKQvIA015850 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Oct 2016 20:26:58 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u9IKQuVT020596; Tue, 18 Oct 2016 20:26:57 GMT Received: from [192.168.1.4] (/87.18.214.54) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 18 Oct 2016 13:26:55 -0700 Subject: Re: [C++ Patch/RFC] PR 67980 ("left shift count is negative [-Wshift-count-negative] generated for unreachable code") To: "gcc-patches@gcc.gnu.org" References: Cc: Jason Merrill From: Paolo Carlini Message-ID: <40a04c1f-6c98-c3e1-57ac-c672b93e2f49@oracle.com> Date: Tue, 18 Oct 2016 22:26:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes ... sorry, what I sent earlier in fact causes a regression in the libstdc++-v3 testsuite: 23_containers/list/61347.cc. Thus, I'm back to one of my first tries earlier today: a much more conservative change which uses fold_non_dependent_expr only for the purpose of suppressing the unwanted warnings, see the below. Thanks, Paolo. /////////////////// Index: cp/pt.c =================================================================== --- cp/pt.c (revision 241313) +++ cp/pt.c (working copy) @@ -15410,7 +15410,14 @@ if (IF_STMT_CONSTEXPR_P (t) && integer_zerop (tmp)) /* Don't instantiate the THEN_CLAUSE. */; else - RECUR (THEN_CLAUSE (t)); + { + bool inhibit = integer_zerop (fold_non_dependent_expr (tmp)); + if (inhibit) + ++c_inhibit_evaluation_warnings; + RECUR (THEN_CLAUSE (t)); + if (inhibit) + --c_inhibit_evaluation_warnings; + } finish_then_clause (stmt); if (IF_STMT_CONSTEXPR_P (t) && integer_nonzerop (tmp)) @@ -15417,8 +15424,13 @@ /* Don't instantiate the ELSE_CLAUSE. */; else if (ELSE_CLAUSE (t)) { + bool inhibit = integer_nonzerop (fold_non_dependent_expr (tmp)); begin_else_clause (stmt); + if (inhibit) + ++c_inhibit_evaluation_warnings; RECUR (ELSE_CLAUSE (t)); + if (inhibit) + --c_inhibit_evaluation_warnings; finish_else_clause (stmt); } Index: testsuite/g++.dg/cpp1y/pr67980.C =================================================================== --- testsuite/g++.dg/cpp1y/pr67980.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr67980.C (working copy) @@ -0,0 +1,23 @@ +// { dg-do compile { target c++14 } } + +template +constexpr T cpp14_constexpr_then(T value) { + if (Y < 0) + return (value << -Y); + else + return 0; +} + +template +constexpr T cpp14_constexpr_else(T value) { + if (Y > 0) + return 0; + else + return (value << -Y); +} + +int main() +{ + cpp14_constexpr_then<1>(0); + cpp14_constexpr_else<1>(0); +}