From patchwork Wed Mar 12 22:17:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 329724 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 4D2592C00AB for ; Thu, 13 Mar 2014 09:18:17 +1100 (EST) 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=yqQ679HMnzkoiMula S+Yj99Zd65UBAG0j9FvKpfyv97sXrOduTHE3F+mNvLEWhXjBEfZAjvYikC9fXy5V RlqZZf/mQx4z8oLuvfhO5XNi9ZOnFap9KLtCtMaczZyhcx35kE3GRcSQ0Zj9eOEi AAyTF0jXGs82WmYX8Ji2L7pb+A= 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=rsFQqWA07MXekSj7UKrsrjl YvWE=; b=R2f6b9i+Vg8VZ1PV8xj7wEgZ/hRHrqkLP5gM5zbq6g+YTBspDLq8t4Q 2V8eZ07NS5Y2gV635jkLPVxH5PJzHQK40HJUJuws+WXiZdIkxkY29h9/dlKTPClx lS3NdLdVPbtryJG8xxUqIJ14lbGIzieF53I/xevN/5vlIbuteuio= Received: (qmail 29001 invoked by alias); 12 Mar 2014 22:18: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 28991 invoked by uid 89); 12 Mar 2014 22:18:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, FSL_NEW_HELO_USER, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no 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; Wed, 12 Mar 2014 22:18:08 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s2CMI5RP002838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 12 Mar 2014 22:18:06 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2CMI4s9003312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 12 Mar 2014 22:18:05 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2CMI4FA003305; Wed, 12 Mar 2014 22:18:04 GMT Received: from [192.168.1.4] (/79.36.196.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 12 Mar 2014 15:18:04 -0700 Message-ID: <5320DCEE.3010909@oracle.com> Date: Wed, 12 Mar 2014 23:17:18 +0100 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch/RFC] PR 60254 References: <53205CC1.6070603@oracle.com> <532076BA.5080706@redhat.com> <53208783.2090008@oracle.com> <5320D17B.5030804@redhat.com> In-Reply-To: <5320D17B.5030804@redhat.com> X-IsSubscribed: yes Hi, On 03/12/2014 10:28 PM, Jason Merrill wrote: > On 03/12/2014 12:12 PM, Paolo Carlini wrote: >> - cxx_constant_value (condition); >> + require_potential_rvalue_constant_expression (condition); > > We need both, actually; cxx_constant_value catches some cases that the > other doesn't. Ok, I think I got confused when I compared to cxx_alignas_expr: in the present case 'condition' is already the result of maybe_constant_value (thus it seems we would waste work) but, at variance with cxx_constant_value called by the former, it allows for nonconstants, and we want to emit at this point also the errors suppressed the first time cxx_eval_outermost_constant_expr is called... Thanks for your patience, now the various *_constant_* helpers are more clear ;) The below also passes testing. Thanks, Paolo. /////////////////// Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 208507) +++ cp/semantics.c (working copy) @@ -6860,7 +6860,8 @@ finish_static_assert (tree condition, tree message else if (condition && condition != error_mark_node) { error ("non-constant condition for static assertion"); - cxx_constant_value (condition); + if (require_potential_rvalue_constant_expression (condition)) + cxx_constant_value (condition); } input_location = saved_loc; } Index: testsuite/g++.dg/cpp0x/static_assert10.C =================================================================== --- testsuite/g++.dg/cpp0x/static_assert10.C (revision 0) +++ testsuite/g++.dg/cpp0x/static_assert10.C (working copy) @@ -0,0 +1,8 @@ +// PR c++/60254 +// { dg-do compile { target c++11 } } + +template bool foo(T) +{ + int i; + static_assert(foo(i), "Error"); // { dg-error "non-constant condition|not usable" } +} Index: testsuite/g++.dg/cpp0x/static_assert11.C =================================================================== --- testsuite/g++.dg/cpp0x/static_assert11.C (revision 0) +++ testsuite/g++.dg/cpp0x/static_assert11.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/60254 +// { dg-do compile { target c++11 } } + +struct A +{ + template bool foo(T) + { + static_assert(foo(0), "Error"); // { dg-error "non-constant condition|constant expression" } + } +}; Index: testsuite/g++.dg/cpp0x/static_assert3.C =================================================================== --- testsuite/g++.dg/cpp0x/static_assert3.C (revision 208507) +++ testsuite/g++.dg/cpp0x/static_assert3.C (working copy) @@ -1,4 +1,4 @@ // { dg-do compile { target c++11 } } static_assert(7 / 0, "X"); // { dg-error "non-constant condition" "non-constant" } // { dg-warning "division by zero" "zero" { target *-*-* } 2 } -// { dg-error "7 / 0.. is not a constant expression" "not a constant" { target *-*-* } 2 } +// { dg-error "division by zero is not a constant-expression" "not a constant" { target *-*-* } 2 }