public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: C++ PATCH for c++/51747 (list-initialization from same type)
Date: Thu, 07 May 2015 16:45:00 -0000	[thread overview]
Message-ID: <554B96A2.4080108@redhat.com> (raw)
In-Reply-To: <53483236.7030700@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 93 bytes --]

We also need to adjust digest_init_r.

Tested x86_64-pc-linux-gnu, applying to trunk and 5.


[-- Attachment #2: 51747-2.patch --]
[-- Type: text/x-patch, Size: 1486 bytes --]

commit 23cbda06982fbaf061719dff124ae90c3b033d7e
Author: Jason Merrill <jason@redhat.com>
Date:   Wed May 6 17:11:54 2015 -0500

    	DR 1467
    	PR c++/51747
    	* typeck2.c (digest_init_r): Fix single element list.

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 6e0c777..076f9a0 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1096,6 +1096,19 @@ digest_init_r (tree type, tree init, bool nested, int flags,
 	      || TREE_CODE (type) == UNION_TYPE
 	      || TREE_CODE (type) == COMPLEX_TYPE);
 
+  /* "If T is a class type and the initializer list has a single
+     element of type cv U, where U is T or a class derived from T,
+     the object is initialized from that element."  */
+  if (cxx_dialect >= cxx11
+      && BRACE_ENCLOSED_INITIALIZER_P (init)
+      && CONSTRUCTOR_NELTS (init) == 1
+      && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type)))
+    {
+      tree elt = CONSTRUCTOR_ELT (init, 0)->value;
+      if (reference_related_p (type, TREE_TYPE (elt)))
+	init = elt;
+    }
+
   if (BRACE_ENCLOSED_INITIALIZER_P (init)
       && !TYPE_NON_AGGREGATE_CLASS (type))
     return process_init_constructor (type, init, complain);
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist95.C b/gcc/testsuite/g++.dg/cpp0x/initlist95.C
new file mode 100644
index 0000000..fe2c8f6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist95.C
@@ -0,0 +1,5 @@
+// PR c++/51747
+// { dg-do compile { target c++11 } }
+
+struct B {};
+struct D : B {D(B b) : B{b} {}};

  parent reply	other threads:[~2015-05-07 16:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-11 18:19 Jason Merrill
2014-04-14 22:03 ` Marc Glisse
2014-04-15 14:01   ` Jason Merrill
2014-04-15 14:13     ` Marc Glisse
2014-04-15 14:59       ` Jason Merrill
2014-04-15 21:02         ` Marc Glisse
2014-04-16 17:26           ` Jason Merrill
2015-05-07 16:45 ` Jason Merrill [this message]
2015-06-09 17:07   ` Jason Merrill

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=554B96A2.4080108@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).