From patchwork Sun Mar 17 02:08:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 228268 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]) by ozlabs.org (Postfix) with SMTP id 5D28C2C00AE for ; Sun, 17 Mar 2013 13:09:09 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1364090951; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=9Fct9DJ U0odPZZYkONznTrZG3Gs=; b=vdCdhOLPq72UVc7U17YNPwwE3/Z4rKMTiwFe9dV yg2N+tG3cLUIB8gOEPOoHOeGG2Ni42X2bpuOd8mo0StNpNXgp5tGePY/wZ+oLLLy FFPNKioxhEnCKk7EKankyLVjwYy4aQd4wWD+iJlqt5T1emEudKosvrIYVxi8rOj4 FCOg= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=fHHUzEdn8tdBlPaFPUKRzR/Yw2IRaHBOhtVzXAZG3F4BnhFgiNi8vJvlX9oDyJ JK3OZYcpmn4X6nGnVtBfQShrAvdBWMQoGcvOlm0iWS6v0k2kVR0mxTqo3OMJhqG4 XNn2NYdQqJDaLfmUGuEgw1+zaTox0ocYDCf94/Nnf+Fx0=; Received: (qmail 13330 invoked by alias); 17 Mar 2013 02:09:04 -0000 Received: (qmail 13321 invoked by uid 22791); 17 Mar 2013 02:09:03 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 17 Mar 2013 02:08:52 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2H28pF8013279 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 16 Mar 2013 22:08:51 -0400 Received: from [10.3.113.56] (ovpn-113-56.phx2.redhat.com [10.3.113.56]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2H28oP0014363 for ; Sat, 16 Mar 2013 22:08:51 -0400 Message-ID: <514525B2.6090104@redhat.com> Date: Sat, 16 Mar 2013 22:08:50 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55931 (ICE with non-dependent constexpr call in template) 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 We were calling fold_non_dependent_expr twice on the template argument, which leads to chaos. In general we try to fold close to the use, so let's stop folding in the parser. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4240d0bfcd28f4a822ae0fff3f045e2eda46f55c Author: Jason Merrill Date: Tue Feb 12 23:40:45 2013 -0500 PR c++/55931 * parser.c (cp_parser_template_argument): Don't fold_non_dependent_expr. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8b6dbe1..0222e90 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13335,7 +13335,6 @@ cp_parser_template_argument (cp_parser* parser) argument = cp_parser_constant_expression (parser, /*allow_non_constant_p=*/false, /*non_constant_p=*/NULL); - argument = fold_non_dependent_expr (argument); if (!maybe_type_id) return argument; if (!cp_parser_next_token_ends_template_argument_p (parser)) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-template4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-template4.C new file mode 100644 index 0000000..7adcae8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-template4.C @@ -0,0 +1,26 @@ +// PR c++/55931 +// { dg-do compile { target c++11 } } + +#include + +template +class Test +{ + public: + constexpr Test(const Type val) : _value(val) {} + constexpr Type get() const {return _value;} + static void test() + { + static constexpr Test x(42); + std::integral_constant i; // This is not working + } + protected: + Type _value; +}; + +int main() +{ + static constexpr Test x(42); + std::integral_constant i; // This is working + Test::test(); +}