aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-04-11 14:25:02 -0400
committerJason Merrill <jason@gcc.gnu.org>2014-04-11 14:25:02 -0400
commit1c982d13138ee4518db10b6fbe02fa32d09ab51e (patch)
treea074cb35215199e5dac65931f9401c12b44db9f2
parent7d0039a6fcd8fa25cf699c8a1ea30f8f8a92a8e7 (diff)
downloadgcc-1c982d13138ee4518db10b6fbe02fa32d09ab51e.zip
gcc-1c982d13138ee4518db10b6fbe02fa32d09ab51e.tar.gz
gcc-1c982d13138ee4518db10b6fbe02fa32d09ab51e.tar.bz2
DR 1467 PR c++/51747
DR 1467 PR c++/51747 * decl.c (reshape_init_r): Handle a single element of class type. From-SVN: r209314
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/decl.c12
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist83.C7
-rw-r--r--gcc/testsuite/g++.dg/init/aggr4.C2
4 files changed, 24 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 04e4787..a1cadeb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2014-04-11 Jason Merrill <jason@redhat.com>
+ DR 1467
+ PR c++/51747
+ * decl.c (reshape_init_r): Handle a single element of class type.
+
DR 1338
* decl.c (cxx_init_decl_processing): Set DECL_IS_MALLOC on
built-in operator new.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 069b374..f8ae07c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5405,6 +5405,18 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p,
return init;
}
+ /* "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." Even if T is an aggregate. */
+ if (cxx_dialect >= cxx11 && CLASS_TYPE_P (type)
+ && first_initializer_p
+ && d->end - d->cur == 1
+ && reference_related_p (type, TREE_TYPE (init)))
+ {
+ d->cur++;
+ return init;
+ }
+
/* [dcl.init.aggr]
All implicit type conversions (clause _conv_) are considered when
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist83.C b/gcc/testsuite/g++.dg/cpp0x/initlist83.C
new file mode 100644
index 0000000..4a5eeb6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist83.C
@@ -0,0 +1,7 @@
+// DR 1467, c++/51747
+// { dg-do compile { target c++11 } }
+
+struct X { };
+
+X x;
+X x2{x};
diff --git a/gcc/testsuite/g++.dg/init/aggr4.C b/gcc/testsuite/g++.dg/init/aggr4.C
index 7120e68..b0eae2e 100644
--- a/gcc/testsuite/g++.dg/init/aggr4.C
+++ b/gcc/testsuite/g++.dg/init/aggr4.C
@@ -4,4 +4,4 @@ struct A
};
A a1 = { 1 }; // ok
-A a2 = { a1 }; // { dg-error "cannot convert" }
+A a2 = { a1 }; // { dg-error "cannot convert" "" { target { ! c++11 } } }