From patchwork Wed Mar 12 16:12:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 329541 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 AF3552C00A2 for ; Thu, 13 Mar 2014 03:13:49 +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=qunaZDDZ4+9+/KYUp pHAtjHuHmHPC+ddOLre+gPu//z+9CVGE0ygyfGf2dJoxnJG0yVl9BvfhDib9CL6/ vfnR1NtMrAfYvU97hFGGybvgLa/Cxnzlyv+hfDiyh8VOjLem+XnhlLXcK8admZM1 C5Wgxo7gxogL1HlajkdeUZUgRw= 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=9PHNPFcTpLD/HZDqrzB3RW8 6w+g=; b=KErgO9QU3quwp+J9rzHnqedSrW+uiyVjgZGPx+A/csYQytWKn/xmXD6 2moM4ArRZuCn155gOzqLcmPjbY3L0jmwkpZduro053JealyC6BfzQ7f3z8IxzLip GuchUw7mnnwEhFUB3Jr7vBoOnUnl4nxwlptB6Vk43AJmg8eREeq4= Received: (qmail 5218 invoked by alias); 12 Mar 2014 16:13:42 -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 5204 invoked by uid 89); 12 Mar 2014 16:13:41 -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 16:13:40 +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 s2CGDcLe029457 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 12 Mar 2014 16:13:39 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s2CGDbIU011269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 12 Mar 2014 16:13:38 GMT Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s2CGDbbh006404; Wed, 12 Mar 2014 16:13:37 GMT Received: from [192.168.1.4] (/79.36.196.111) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 12 Mar 2014 09:13:37 -0700 Message-ID: <53208783.2090008@oracle.com> Date: Wed, 12 Mar 2014 17:12:51 +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> In-Reply-To: <532076BA.5080706@redhat.com> X-IsSubscribed: yes Hi, On 03/12/2014 04:01 PM, Jason Merrill wrote: > Perhaps we need a require_potential_rvalue_constant_expression? Something like the below? Interesting, that should also save some duplicate work. Note however, that, besides the trivial adjustment of static_assert3.C, we produce slightly different secondary diagnostic for both static_assert10.C and static_assert11.C: for the former we notice the non-constant 'int i' (*), for the latter the use of 'this'. Is that Ok? Thanks, Paolo. ////////////////// (*) I double checked that if 'int i' is changed to 'const int i = 0' we provide indeed the error message about the non-constexpr 'foo' as secondary error message. Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 208507) +++ cp/semantics.c (working copy) @@ -6860,7 +6860,7 @@ 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); + require_potential_rvalue_constant_expression (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" "non-constant" { target *-*-* } 2 }