OSDN Git Service

PR c++/45315
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 Aug 2010 17:01:01 +0000 (17:01 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 Aug 2010 17:01:01 +0000 (17:01 +0000)
* init.c (build_new_1): Don't use build_value_init in a template.
(build_value_init): Make sure we don't.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@163381 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/value8.C [new file with mode: 0644]

index 7667bb6..bac1182 100644 (file)
@@ -1,5 +1,9 @@
 2010-08-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/45315
+       * init.c (build_new_1): Don't use build_value_init in a template.
+       (build_value_init): Make sure we don't.
+
        PR c++/45307
        * cp-gimplify.c (cp_gimplify_expr): Also remove assignment
        of empty class CONSTRUCTOR.
index 8555fad..189bcbe 100644 (file)
@@ -295,6 +295,9 @@ build_value_init (tree type, tsubst_flags_t complain)
      zero-initializing the object and then calling the default
      constructor.  */
 
+  /* The AGGR_INIT_EXPR tweaking below breaks in templates.  */
+  gcc_assert (!processing_template_decl);
+
   if (CLASS_TYPE_P (type))
     {
       if (type_has_user_provided_constructor (type))
@@ -2310,7 +2313,8 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts,
        {
          init_expr = cp_build_indirect_ref (data_addr, RO_NULL, complain);
 
-         if (TYPE_NEEDS_CONSTRUCTING (type) && !explicit_value_init_p)
+         if (TYPE_NEEDS_CONSTRUCTING (type)
+             && (!explicit_value_init_p || processing_template_decl))
            {
              init_expr = build_special_member_call (init_expr,
                                                     complete_ctor_identifier,
@@ -2320,11 +2324,17 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts,
            }
          else if (explicit_value_init_p)
            {
-             /* Something like `new int()'.  */
-             tree val = build_value_init (type, complain);
-             if (val == error_mark_node)
-               return error_mark_node;
-             init_expr = build2 (INIT_EXPR, type, init_expr, val);
+             if (processing_template_decl)
+               /* Don't worry about it, we'll handle this properly at
+                  instantiation time.  */;
+             else
+               {
+                 /* Something like `new int()'.  */
+                 tree val = build_value_init (type, complain);
+                 if (val == error_mark_node)
+                   return error_mark_node;
+                 init_expr = build2 (INIT_EXPR, type, init_expr, val);
+               }
            }
          else
            {
index 289a124..805cd7a 100644 (file)
@@ -1,5 +1,7 @@
 2010-08-19  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/init/value8.C: New.
+
        * g++.dg/tree-ssa/empty-2.C: New.
 
        * g++.dg/cpp0x/noexcept09.C: New.
diff --git a/gcc/testsuite/g++.dg/init/value8.C b/gcc/testsuite/g++.dg/init/value8.C
new file mode 100644 (file)
index 0000000..0a9b90b
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/45315
+
+struct A
+{
+  A ();
+};
+
+template < int > struct B : A
+{
+  void foo ()
+  {
+    new B < 0 > ();
+  }
+};
+
+int main()
+{
+  B<1>().foo();
+}