From patchwork Wed Sep 7 17:05:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 113802 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 B712DB6F92 for ; Thu, 8 Sep 2011 03:05:38 +1000 (EST) Received: (qmail 1222 invoked by alias); 7 Sep 2011 17:05:34 -0000 Received: (qmail 1207 invoked by uid 22791); 7 Sep 2011 17:05:32 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Wed, 07 Sep 2011 17:05:16 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p87H5FKp028980 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Sep 2011 13:05:16 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p87H5F0Y018823 for ; Wed, 7 Sep 2011 13:05:15 -0400 Received: from [0.0.0.0] (ovpn-113-157.phx2.redhat.com [10.3.113.157]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p87H5EOq016079 for ; Wed, 7 Sep 2011 13:05:14 -0400 Message-ID: <4E67A449.4020702@redhat.com> Date: Wed, 07 Sep 2011 13:05:13 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20110817 Thunderbird/6.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50298 (static constexpr reference in-class initialization) 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 cp_parser_constant_expression wants an rvalue constant, so we shouldn't use it for parsing initializers, since the thing being initialized might be a reference. In C++98 it's OK because only integral statics can be initialized in the class, but in C++11 any type can be with the constexpr tag. Tested x86_64-pc-linux-gnu, applying to trunk. commit 820655889d7ea9f825769286823241fd6d0fbae5 Author: Jason Merrill Date: Tue Sep 6 22:01:35 2011 -0400 PR c++/50298 * parser.c (cp_parser_member_declaration): Don't require a constant rvalue here in C++0x. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7d766d1..6346aa0 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -18187,6 +18187,17 @@ cp_parser_member_declaration (cp_parser* parser) initializer_token_start = cp_lexer_peek_token (parser->lexer); if (function_declarator_p (declarator)) initializer = cp_parser_pure_specifier (parser); + else if (cxx_dialect >= cxx0x) + { + bool nonconst; + /* Don't require a constant rvalue in C++11, since we + might want a reference constant. We'll enforce + constancy later. */ + cp_lexer_consume_token (parser->lexer); + /* Parse the initializer. */ + initializer = cp_parser_initializer_clause (parser, + &nonconst); + } else /* Parse the initializer. */ initializer = cp_parser_constant_initializer (parser); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ref3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref3.C new file mode 100644 index 0000000..24cc9c8 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref3.C @@ -0,0 +1,10 @@ +// PR c++/50298 +// { dg-options -std=c++0x } + +int global_variable; + +template struct X { + static constexpr T r = global_variable; +}; + +X x;