Hi,
On 05/20/2014 05:08 PM, Jason Merrill wrote:
On 05/20/2014 10:50 AM, Paolo Carlini wrote:
+ 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);
Instead of this let's factor the relevant code out of
cp_parser_late_parse_one_default_arg and use it here as well.
Indeed. Thus I'm finishing testing the below.
Thanks,
Paolo.
///////////////////////////
/cp
2014-05-20 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58753
PR c++/58930
PR c++/58704
* typeck2.c (digest_nsdmi_init): New.
* parser.c (cp_parser_late_parse_one_default_arg): Use it.
* init.c (get_nsdmi): Likewise.
* cp-tree.h (digest_nsdmi_init): Declare.
/testsuite
2014-05-20 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/58753
PR c++/58930
PR c++/58704
* g++.dg/cpp0x/nsdmi-template11.C: New.
* g++.dg/cpp0x/nsdmi-template12.C: Likewise.
* g++.dg/cpp0x/nsdmi-template13.C: Likewise.
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h (revision 210645)
+++ cp/cp-tree.h (working copy)
@@ -6172,6 +6172,7 @@ extern tree store_init_value (tree,
tree, vec<tr
extern void check_narrowing (tree, tree);
extern tree digest_init (tree, tree,
tsubst_flags_t);
extern tree digest_init_flags (tree, tree, int);
+extern tree digest_nsdmi_init (tree, tree);
extern tree build_scoped_ref (tree, tree, tree *);
extern tree build_x_arrow (location_t, tree,
tsubst_flags_t);
Index: cp/init.c
===================================================================
--- cp/init.c (revision 210645)
+++ cp/init.c (working copy)
@@ -534,12 +534,16 @@ get_nsdmi (tree member, bool in_ctor)
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));
+
+ init = digest_nsdmi_init (member, init);
+ }
else
{
init = DECL_INITIAL (member);
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 210645)
+++ cp/parser.c (working copy)
@@ -23681,15 +23681,7 @@ cp_parser_late_parse_one_default_arg (cp_parser *p
parsed_arg = check_default_argument (parmtype, parsed_arg,
tf_warning_or_error);
else
- {
- int flags = LOOKUP_IMPLICIT;
- if (DIRECT_LIST_INIT_P (parsed_arg))
- flags = LOOKUP_NORMAL;
- parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
- if (TREE_CODE (parsed_arg) == TARGET_EXPR)
- /* This represents the whole initialization. */
- TARGET_EXPR_DIRECT_INIT_P (parsed_arg) = true;
- }
+ parsed_arg = digest_nsdmi_init (decl, parsed_arg);
}
/* If the token stream has not been completely used up, then
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 210645)
+++ cp/typeck2.c (working copy)
@@ -1114,6 +1114,22 @@ digest_init_flags (tree type, tree init, int flags
{
return digest_init_r (type, init, false, flags, tf_warning_or_error);
}
+
+/* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL). */
+tree
+digest_nsdmi_init (tree decl, tree init)
+{
+ gcc_assert (TREE_CODE (decl) == FIELD_DECL);
+
+ int flags = LOOKUP_IMPLICIT;
+ if (DIRECT_LIST_INIT_P (init))
+ flags = LOOKUP_NORMAL;
+ init = digest_init_flags (TREE_TYPE (decl), init, flags);
+ if (TREE_CODE (init) == TARGET_EXPR)
+ /* This represents the whole initialization. */
+ TARGET_EXPR_DIRECT_INIT_P (init) = true;
+ return init;
+}
/* Set of flags used within process_init_constructor to describe the
initializers. */
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;
+}
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<typename> struct B
+{
+ A a[1] = { };
+};
+
+B<int> b;