From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 181FF385734E; Sun, 15 May 2022 16:28:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 181FF385734E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-463] c++: array {}-init [PR105589] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: c5397682aff4ae9ced15ddc74971b9b6e218b664 X-Git-Newrev: ce46d6041358052dfa26f3720732f0357c5d72e7 Message-Id: <20220515162823.181FF385734E@sourceware.org> Date: Sun, 15 May 2022 16:28:23 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 May 2022 16:28:23 -0000 https://gcc.gnu.org/g:ce46d6041358052dfa26f3720732f0357c5d72e7 commit r13-463-gce46d6041358052dfa26f3720732f0357c5d72e7 Author: Jason Merrill Date: Fri May 13 16:07:10 2022 -0400 c++: array {}-init [PR105589] My patch for 105191 made us use build_value_init more frequently from build_vec_init_expr, but build_value_init doesn't like to be called to initialize a class in a template. That's caused trouble in the past, and seems like a strange restriction, so let's fix it. PR c++/105589 PR c++/105191 PR c++/92385 gcc/cp/ChangeLog: * init.cc (build_value_init): Handle class in template. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-array16.C: New test. Diff: --- gcc/cp/init.cc | 7 +++---- gcc/testsuite/g++.dg/cpp0x/initlist-array16.C | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index f1ed9336dc9..a4a0a0ac0c2 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -343,10 +343,6 @@ build_value_init (tree type, tsubst_flags_t complain) A program that calls for default-initialization or value-initialization of an entity of reference type is ill-formed. */ - /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ - gcc_assert (!processing_template_decl - || (SCALAR_TYPE_P (type) || TREE_CODE (type) == ARRAY_TYPE)); - if (CLASS_TYPE_P (type) && type_build_ctor_call (type)) { tree ctor @@ -354,6 +350,9 @@ build_value_init (tree type, tsubst_flags_t complain) NULL, type, LOOKUP_NORMAL, complain); if (ctor == error_mark_node || TREE_CONSTANT (ctor)) return ctor; + if (processing_template_decl) + /* The AGGR_INIT_EXPR tweaking below breaks in templates. */ + return build_min (CAST_EXPR, type, NULL_TREE); tree fn = NULL_TREE; if (TREE_CODE (ctor) == CALL_EXPR) fn = get_callee_fndecl (ctor); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array16.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array16.C new file mode 100644 index 00000000000..bb1d8d84704 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array16.C @@ -0,0 +1,11 @@ +// PR c++/105589 +// { dg-do compile { target c++11 } } + +struct X { X(); }; + +struct array { X m[2]; }; + +template +void f() { + array w = array{}; +}