We also need to adjust digest_init_r.

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

commit 23cbda06982fbaf061719dff124ae90c3b033d7e
Author: Jason Merrill <ja...@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} {}};

Reply via email to