From patchwork Tue Nov 11 13:04:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 409427 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 A253B14017C for ; Wed, 12 Nov 2014 00:05:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=evMZR327Z7uEhQmgb vqfVOix85/ozJhav7bheDCVaMEjvOb74Bk5gFRNGbbACOCztLfrGWfYGvy8p9oFu T+7PBPkJ+IfzeONjrlbmejWSXyUSRyMZo3z6nhTGvtVYJffwOJg6NbLT23M9+F70 UoMGYAW7leHraW3KdPc6Nf87wg= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=yp4s9ZF3CfBmOnQBcJund9Y 9/Vk=; b=Fh7EMvn8mP4OoCUzRrT3I7nzCwEYf407ZrjtGbG9HH77Kls9DwQI6m2 rTMQb+Wl79T0FqEOyeEzXlET1OLY0L7BctESXp4f+85/zr0Dcb/TXTektbgkpVBN OEOXiTFcZrcO602xfgfli3C4FNQj/dlIz3Q59b+mk46850Bc4b5c= Received: (qmail 10494 invoked by alias); 11 Nov 2014 13:04:54 -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 10384 invoked by uid 89); 11 Nov 2014 13:04:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 11 Nov 2014 13:04:52 +0000 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id sABD4nlj003453 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Nov 2014 13:04:50 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sABD4nAi026446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 11 Nov 2014 13:04:49 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id sABD4mx9026426; Tue, 11 Nov 2014 13:04:48 GMT Received: from [192.168.1.4] (/79.12.219.197) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 11 Nov 2014 05:04:48 -0800 Message-ID: <5462096E.9090308@oracle.com> Date: Tue, 11 Nov 2014 14:04:46 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 63265 References: <5460E8B1.1030405@oracle.com> <5460F2E0.5040801@redhat.com> In-Reply-To: <5460F2E0.5040801@redhat.com> X-IsSubscribed: yes Hi, On 11/10/2014 06:16 PM, Jason Merrill wrote: > I don't think we want to suppress this warning in general. The > problem in this PR is that the warning code is failing to recognize > that the first operand is constant false. Thanks. Then, shall we do something like the below? Passes testing. Thanks, Paolo. ////////////////// /cp 2014-11-11 Paolo Carlini PR c++/63265 * pt.c (tsubst_copy_and_build, case COND_EXPR): Maybe fold to const the condition. /testsuite 2014-11-11 Paolo Carlini PR c++/63265 * g++.dg/cpp0x/constexpr-63265.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 217342) +++ cp/pt.c (working copy) @@ -15137,7 +15137,9 @@ tsubst_copy_and_build (tree t, case COND_EXPR: { - tree cond = RECUR (TREE_OPERAND (t, 0)); + tree cond + = maybe_constant_value (fold_non_dependent_expr_sfinae + (RECUR (TREE_OPERAND (t, 0)), tf_none)); tree exp1, exp2; if (TREE_CODE (cond) == INTEGER_CST) Index: testsuite/g++.dg/cpp0x/constexpr-63265.C =================================================================== --- testsuite/g++.dg/cpp0x/constexpr-63265.C (revision 0) +++ testsuite/g++.dg/cpp0x/constexpr-63265.C (working copy) @@ -0,0 +1,19 @@ +// PR c++/63265 +// { dg-do compile { target c++11 } } + +#define LSHIFT (sizeof(unsigned int) * __CHAR_BIT__) + +template +struct SpuriouslyWarns1 { + static constexpr unsigned int v = lshift < LSHIFT ? 1U << lshift : 0; +}; + +static_assert(SpuriouslyWarns1::v == 0, "Impossible occurred"); + +template +struct SpuriouslyWarns2 { + static constexpr bool okay = lshift < LSHIFT; + static constexpr unsigned int v = okay ? 1U << lshift : 0; +}; + +static_assert(SpuriouslyWarns2::v == 0, "Impossible occurred");