From patchwork Wed Dec 8 22:50:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 74786 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 64CD9B70A7 for ; Thu, 9 Dec 2010 09:50:32 +1100 (EST) Received: (qmail 2554 invoked by alias); 8 Dec 2010 22:50:30 -0000 Received: (qmail 2482 invoked by uid 22791); 8 Dec 2010 22:50:28 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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, 08 Dec 2010 22:50:21 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB8MoJPU016041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 8 Dec 2010 17:50:19 -0500 Received: from [127.0.0.1] (ovpn-113-131.phx2.redhat.com [10.3.113.131]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oB8MoIfd015443 for ; Wed, 8 Dec 2010 17:50:18 -0500 Message-ID: <4D000BA9.2010806@redhat.com> Date: Wed, 08 Dec 2010 17:50:17 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20101202 Lightning/1.0b1 Shredder/3.0.11pre MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/46348 (array value-init and constexpr) 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 When I added VEC_INIT_EXPR_VALUE_INIT, I mysteriously failed to adjust the constexpr expander to handle it. Fixed thus. Tested x86_64-pc-linux-gnu, applied to trunk. commit d5c6e45e1c2986dd605e175637d6748ba6492d7b Author: Jason Merrill Date: Wed Dec 8 15:17:24 2010 -0500 PR c++/46348 * semantics.c (cxx_eval_vec_init_1): Handle value-init. (cxx_eval_vec_init): Pass value_init arg. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1ee0ccf..db0d0a1 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6391,15 +6391,16 @@ cxx_eval_bare_aggregate (const constexpr_call *call, tree t, initialization of a non-static data member of array type. Reduce it to a CONSTRUCTOR. - Note that this is only intended to support the initializations done by - defaulted constructors for classes with non-static data members of array - type. In this case, VEC_INIT_EXPR_INIT will either be NULL_TREE for the - default constructor, or a COMPONENT_REF for the copy/move - constructor. */ + Note that apart from value-initialization (when VALUE_INIT is true), + this is only intended to support value-initialization and the + initializations done by defaulted constructors for classes with + non-static data members of array type. In this case, VEC_INIT_EXPR_INIT + will either be NULL_TREE for the default constructor, or a COMPONENT_REF + for the copy/move constructor. */ static tree cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init, - bool allow_non_constant, bool addr, + bool value_init, bool allow_non_constant, bool addr, bool *non_constant_p) { tree elttype = TREE_TYPE (atype); @@ -6412,7 +6413,9 @@ cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init, here, as for a constructor to be constexpr, all members must be initialized, which for a defaulted default constructor means they must be of a class type with a constexpr default constructor. */ - if (!init) + if (value_init) + gcc_assert (!init); + else if (!init) { VEC(tree,gc) *argvec = make_tree_vector (); init = build_special_member_call (NULL_TREE, complete_ctor_identifier, @@ -6433,12 +6436,21 @@ cxx_eval_vec_init_1 (const constexpr_call *call, tree atype, tree init, if (TREE_CODE (elttype) == ARRAY_TYPE) { /* A multidimensional array; recurse. */ - eltinit = cp_build_array_ref (input_location, init, idx, - tf_warning_or_error); - eltinit = cxx_eval_vec_init_1 (call, elttype, eltinit, + if (value_init) + eltinit = NULL_TREE; + else + eltinit = cp_build_array_ref (input_location, init, idx, + tf_warning_or_error); + eltinit = cxx_eval_vec_init_1 (call, elttype, eltinit, value_init, allow_non_constant, addr, non_constant_p); } + else if (value_init) + { + eltinit = build_value_init (elttype, tf_warning_or_error); + eltinit = cxx_eval_constant_expression + (call, eltinit, allow_non_constant, addr, non_constant_p); + } else if (TREE_CODE (init) == CONSTRUCTOR) { /* Initializing an element using the call to the default @@ -6488,8 +6500,9 @@ cxx_eval_vec_init (const constexpr_call *call, tree t, { tree atype = TREE_TYPE (t); tree init = VEC_INIT_EXPR_INIT (t); - tree r = cxx_eval_vec_init_1 (call, atype, init, allow_non_constant, - addr, non_constant_p); + tree r = cxx_eval_vec_init_1 (call, atype, init, + VEC_INIT_EXPR_VALUE_INIT (t), + allow_non_constant, addr, non_constant_p); if (*non_constant_p) return t; else diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array2.C new file mode 100644 index 0000000..9577f75 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array2.C @@ -0,0 +1,19 @@ +// PR c++/46348 +// { dg-options -std=c++0x } + +template<__SIZE_TYPE__ _Nw> + struct _Base + { + typedef unsigned long _WordT; + + _WordT _M_w[_Nw]; + + constexpr + _Base() + : _M_w() { } + }; + +int main() +{ + _Base<256> bs; +}