Hi,
I'm trying to make progress on these two issues, which seem closely
related to me. Both only happen for NSDMIs in template classes, thus
when cp_parser_late_parse_one_default_arg sees processing_template_decl
!= 0 and doesn't call digest_init_flags directly, thus produces a
CONSTRUCTOR (vs, eg, a TARGET_EXPR). Then, I think that the problem -
thus the incorrect diagnostic and the rejection - must be in
perform_member_init, which doesn't early handle such CONSTRUCTOR with
DIRECT_LIST_INIT_P true, thus doesn't call digest_init. The below passes
testing and fixes all the snippets we have got for those two PRs.
Thanks!
Paolo.
////////////////////
Index: cp/init.c
===================================================================
--- cp/init.c (revision 210459)
+++ cp/init.c (working copy)
@@ -644,7 +644,9 @@ perform_member_init (tree member, tree init)
|| (TREE_CODE (init) == TREE_LIST
&& DIRECT_LIST_INIT_P (TREE_VALUE (init))))
&& (CP_AGGREGATE_TYPE_P (type)
- || is_std_init_list (type)))))
+ || is_std_init_list (type)))
+ /* This can happen for NSDMI in template class (c++/58930). */
+ || DIRECT_LIST_INIT_P (init)))
{
/* With references and list-initialization, we need to deal with
extending temporary lifetimes. 12.2p5: "A temporary bound to a
Index: testsuite/g++.dg/cpp0x/nsdmi-template11.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template11.C (revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template11.C (working copy)
@@ -0,0 +1,15 @@
+// PR c++/58930
+// { dg-do compile { target c++11 } }
+
+struct SampleModule
+{
+ explicit SampleModule (int);
+};
+
+template < typename >
+struct BaseHandler
+{
+ SampleModule module_ { 0 };
+};
+
+BaseHandler<int> a;
Index: testsuite/g++.dg/cpp0x/nsdmi-template12.C
===================================================================
--- testsuite/g++.dg/cpp0x/nsdmi-template12.C (revision 0)
+++ testsuite/g++.dg/cpp0x/nsdmi-template12.C (working copy)
@@ -0,0 +1,17 @@
+// PR c++/58753
+// { dg-do compile { target c++11 } }
+
+#include <initializer_list>
+
+template <class T>
+struct X {X(std::initializer_list<int>) {}};
+
+template <class zomg>
+class T {
+ X<T> x{1};
+};
+
+int main()
+{
+ T<int> t;
+}