Index: cp/init.c =================================================================== --- cp/init.c (revision 210641) +++ cp/init.c (working copy) @@ -529,17 +529,28 @@ tree get_nsdmi (tree member, bool in_ctor) { tree init; + tree type = TREE_TYPE (member); tree save_ccp = current_class_ptr; tree save_ccr = current_class_ref; if (!in_ctor) inject_this_parameter (DECL_CONTEXT (member), TYPE_UNQUALIFIED); if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) - /* Do deferred instantiation of the NSDMI. */ - init = (tsubst_copy_and_build - (DECL_INITIAL (DECL_TI_TEMPLATE (member)), - DECL_TI_ARGS (member), - tf_warning_or_error, member, /*function_p=*/false, - /*integral_constant_expression_p=*/false)); + { + /* Do deferred instantiation of the NSDMI. */ + init = (tsubst_copy_and_build + (DECL_INITIAL (DECL_TI_TEMPLATE (member)), + DECL_TI_ARGS (member), + tf_warning_or_error, member, /*function_p=*/false, + /*integral_constant_expression_p=*/false)); + + if (TREE_TYPE (init) != type) + { + if (BRACE_ENCLOSED_INITIALIZER_P (init) + && CP_AGGREGATE_TYPE_P (type)) + init = reshape_init (type, init, tf_warning_or_error); + init = digest_init (type, init, tf_warning_or_error); + } + } else { init = DECL_INITIAL (member); 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 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 + +template +struct X {X(std::initializer_list) {}}; + +template +class T { + X x{1}; +}; + +int main() +{ + T t; +} Index: testsuite/g++.dg/cpp0x/nsdmi-template13.C =================================================================== --- testsuite/g++.dg/cpp0x/nsdmi-template13.C (revision 0) +++ testsuite/g++.dg/cpp0x/nsdmi-template13.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/58704 +// { dg-do compile { target c++11 } } + +struct A {}; + +template struct B +{ + A a[1] = { }; +}; + +B b;