In C++11, copy-list-initialization by explicit constructor is an error,
even for the default constructor. But this combined with the change of
aggregate initialization to use {} for any missing initializers means
that well-formed C++03 code becomes ill-formed in C++11. Until the
committee decides what to do about this, let's call the implicit
initializers direct-initialization.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit ea0a530e2164b029909934a1cd4985f8c2bc3b00
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Mar 4 16:16:36 2014 -0500
PR c++/60417
* typeck2.c (process_init_constructor_record): Set
CONSTRUCTOR_IS_DIRECT_INIT on {} for omitted initializers.
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 8877286..3a4caa0 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1312,6 +1312,9 @@ process_init_constructor_record (tree type, tree init,
for us, so build up TARGET_EXPRs. If the type in question is
a class, just build one up; if it's an array, recurse. */
next = build_constructor (init_list_type_node, NULL);
+ /* Call this direct-initialization pending DR 1518 resolution so
+ that explicit default ctors don't break valid C++03 code. */
+ CONSTRUCTOR_IS_DIRECT_INIT (next) = true;
next = massage_init_elt (TREE_TYPE (field), next, complain);
/* Warn when some struct elements are implicitly initialized. */
diff --git a/gcc/testsuite/g++.dg/init/explicit1.C b/gcc/testsuite/g++.dg/init/explicit1.C
new file mode 100644
index 0000000..f376df2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/explicit1.C
@@ -0,0 +1,9 @@
+// PR c++/60417
+
+struct A { explicit A(int = 0); };
+struct B { A a; };
+
+int main()
+{
+ B b = {};
+}