re PR c++/58753 (Brace-initializing a vector with a direct-initialization NSDMI doesn...
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 20 May 2014 19:20:59 +0000 (19:20 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 20 May 2014 19:20:59 +0000 (19:20 +0000)
/cp
2014-05-20  Paolo Carlini  <paolo.carlini@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.carlini@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.

From-SVN: r210653

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/init.c
gcc/cp/parser.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi-template11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi-template12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nsdmi-template13.C [new file with mode: 0644]

index dd183cc..fb0d335 100644 (file)
@@ -1,3 +1,13 @@
+2014-05-20  Paolo Carlini  <paolo.carlini@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.
+
 2014-05-20  Jason Merrill  <jason@redhat.com>
 
        * typeck.c (get_member_function_from_ptrfunc): Don't try to look
index 32a8afb..7d29c2c 100644 (file)
@@ -6172,6 +6172,7 @@ extern tree store_init_value                      (tree, tree, vec<tree, va_gc>**, int);
 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 80764f9..42b25db 100644 (file)
@@ -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 0c9e113..d6bb518 100644 (file)
@@ -23681,15 +23681,7 @@ cp_parser_late_parse_one_default_arg (cp_parser *parser, tree decl,
        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 72995e9..d50d93e 100644 (file)
@@ -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;
+}
 \f
 /* Set of flags used within process_init_constructor to describe the
    initializers.  */
index cdb3d87..121cc19 100644 (file)
@@ -1,3 +1,12 @@
+2014-05-20  Paolo Carlini  <paolo.carlini@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.
+
 2014-05-20  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/opt35.adb: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template11.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template11.C
new file mode 100644 (file)
index 0000000..60e53c4
--- /dev/null
@@ -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;
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template12.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template12.C
new file mode 100644 (file)
index 0000000..5b87f42
--- /dev/null
@@ -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;
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-template13.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-template13.C
new file mode 100644 (file)
index 0000000..65ccd0a
--- /dev/null
@@ -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;