summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2015-05-07 16:46:49 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2015-05-07 16:46:49 +0000
commit3dd2833b51262c109ebc4b6f3f93973c286cd7cd (patch)
treeaa079c4af155d41d03dc21b1e1cc647a61937f1f /gcc
parent1dc4e11613a8272b136453df12f1495c2423bb34 (diff)
downloadgcc-3dd2833b51262c109ebc4b6f3f93973c286cd7cd.tar.gz
DR 1467
PR c++/51747 * typeck2.c (digest_init_r): Fix single element list. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@222881 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck2.c13
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist95.C5
3 files changed, 24 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b1da4fe7e3d..4929faabfd5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2015-05-07 Jason Merrill <jason@redhat.com>
+
+ DR 1467
+ PR c++/51747
+ * typeck2.c (digest_init_r): Fix single element list.
+
2015-05-05 Jason Merrill <jason@redhat.com>
* cp-gimplify.c (cp_genericize_r): Track TRY_BLOCK and
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 6e0c777eac1..076f9a03498 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 00000000000..fe2c8f61ba0
--- /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} {}};