From: Jason Merrill <jason@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [pushed] c++: array {}-init [PR105589]
Date: Sun, 15 May 2022 12:28:12 -0400 [thread overview]
Message-ID: <20220515162812.3970024-1-jason@redhat.com> (raw)
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.
Tested x86_64-pc-linux-gnu, applying to trunk.
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.
---
gcc/cp/init.cc | 7 +++----
gcc/testsuite/g++.dg/cpp0x/initlist-array16.C | 11 +++++++++++
2 files changed, 14 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array16.C
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<class>
+void f() {
+ array w = array{};
+}
base-commit: c5397682aff4ae9ced15ddc74971b9b6e218b664
--
2.27.0
reply other threads:[~2022-05-15 16:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220515162812.3970024-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).