]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/9879 (ICE / endless compile with "new int[2]()")
authorMark Mitchell <mark@codesourcery.com>
Fri, 28 Feb 2003 20:15:34 +0000 (20:15 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 28 Feb 2003 20:15:34 +0000 (20:15 +0000)
PR c++/9879
* cp-tree.h (build_zero_init): Add parameter.
* decl.c (cp_finish_decl): Adjust call.
* init.c (build_zero_init): Add nelts parameter.  Adjust recursive
calls.
(build_default_init): Add nelts parameter.  Adjust calls to
build_zero_init.
(build_new_1): Adjust call to build_default_init.
* typeck2.c (process_init_constructor): Adjust call to build_zero_init.

PR c++/9879
* testsuite/g++.dg/init/new4.C: New test.

From-SVN: r63579

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/init.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/new4.C [new file with mode: 0644]

index b896fb30d200ab4ee7fdd927db003d5fee6426d9..8fd10b17bdf0dbb369aa9731afe99eb83423c035 100644 (file)
@@ -1,3 +1,15 @@
+2003-02-28  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/9879
+       * cp-tree.h (build_zero_init): Add parameter.
+       * decl.c (cp_finish_decl): Adjust call.
+       * init.c (build_zero_init): Add nelts parameter.  Adjust recursive
+       calls.
+       (build_default_init): Add nelts parameter.  Adjust calls to
+       build_zero_init.
+       (build_new_1): Adjust call to build_default_init.
+       * typeck2.c (process_init_constructor): Adjust call to build_zero_init.
+       
 2003-02-26  Devang Patel  <dpatel@apple.com>
 
        * decl.c (finish_enum): Merge two 'for' loops. Copy value node if required.
index 8e44bbb9efc97984625b45cb57cbc245c5780f51..408024838cf11582e75bd8930dd31873402dc71e 100644 (file)
@@ -3912,7 +3912,7 @@ extern tree build_init                            (tree, tree, int);
 extern int is_aggr_type                                (tree, int);
 extern tree get_aggr_from_typedef              (tree, int);
 extern tree get_type_value                     (tree);
-extern tree build_zero_init                    (tree, bool);
+extern tree build_zero_init                    (tree, tree, bool);
 extern tree build_member_call                  (tree, tree, tree);
 extern tree build_offset_ref                   (tree, tree);
 extern tree resolve_offset_ref                 (tree);
index de631813ae80cac97c93137433fcaa8c2ca5c1d5..cd15f25315da52b2c8f40441c9f713f89256aaed 100644 (file)
@@ -8209,6 +8209,7 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags)
             necessary zero-initialization has already been performed.  */
          if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
            DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
+                                                  /*nelts=*/NULL_TREE,
                                                   /*static_storage_p=*/true);
          /* Remember that the initialization for this variable has
             taken place.  */
index 7036aa02fb6475617a08bf0dc3afe264eeb560b3..1b8651392918e68980d5760ec8bc7d4ecfa669fc 100644 (file)
@@ -48,7 +48,7 @@ static tree initializing_context PARAMS ((tree));
 static void expand_cleanup_for_base PARAMS ((tree, tree));
 static tree get_temp_regvar PARAMS ((tree, tree));
 static tree dfs_initialize_vtbl_ptrs PARAMS ((tree, void *));
-static tree build_default_init PARAMS ((tree));
+static tree build_default_init PARAMS ((tree, tree));
 static tree build_new_1        PARAMS ((tree));
 static tree get_cookie_size PARAMS ((tree));
 static tree build_dtor_call PARAMS ((tree, special_function_kind, int));
@@ -159,12 +159,14 @@ initialize_vtbl_ptrs (addr)
    that T is a scalar), or a CONSTRUCTOR (in the case that T is an
    aggregate).  In either case, the value can be used as DECL_INITIAL
    for a decl of the indicated TYPE; it is a valid static initializer.
-   If STATIC_STORAGE_P is TRUE, initializers are only generated for
-   entities for which zero-initialization does not simply mean filling
-   the storage with zero bytes.  */
+   If NELTS is non-NULL, and TYPE is an ARRAY_TYPE, NELTS is the
+   number of elements in the array.  If STATIC_STORAGE_P is TRUE,
+   initializers are only generated for entities for which
+   zero-initialization does not simply mean filling the storage with
+   zero bytes.  */
 
 tree
-build_zero_init (tree type, bool static_storage_p)
+build_zero_init (tree type, tree nelts, bool static_storage_p)
 {
   tree init = NULL_TREE;
 
@@ -217,6 +219,7 @@ build_zero_init (tree type, bool static_storage_p)
          if (static_storage_p && !zero_init_p (TREE_TYPE (field)))
            inits = tree_cons (field, 
                               build_zero_init (TREE_TYPE (field),
+                                               /*nelts=*/NULL_TREE,
                                                static_storage_p),
                               inits);
 
@@ -236,11 +239,13 @@ build_zero_init (tree type, bool static_storage_p)
       init = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
       /* Iterate over the array elements, building initializations.  */
       inits = NULL_TREE;
-      for (index = size_zero_node, max_index = array_type_nelts (type);
+      max_index = nelts ? nelts : array_type_nelts (type);
+      for (index = size_zero_node;
           !tree_int_cst_lt (max_index, index);
           index = size_binop (PLUS_EXPR, index, size_one_node))
        inits = tree_cons (index,
-                          build_zero_init (TREE_TYPE (type), 
+                          build_zero_init (TREE_TYPE (type),
+                                           /*nelts=*/NULL_TREE,
                                            static_storage_p),
                           inits);
       CONSTRUCTOR_ELTS (init) = nreverse (inits);
@@ -257,14 +262,17 @@ build_zero_init (tree type, bool static_storage_p)
   return init;
 }
 
-/* Build an expression for the default-initialization of an object
-   with type T.  If initialization T requires calling constructors,
-   this function returns NULL_TREE; the caller is responsible for
-   arranging for the constructors to be called.  */
+/* Build an expression for the default-initialization of an object of
+   the indicated TYPE.  If NELTS is non-NULL, and TYPE is an
+   ARRAY_TYPE, NELTS is the number of elements in the array.  If
+   initialization of TYPE requires calling constructors, this function
+   returns NULL_TREE; the caller is responsible for arranging for the
+   constructors to be called.  */
 
 static tree
-build_default_init (type)
+build_default_init (type, nelts)
      tree type;
+     tree nelts;
 {
   /* [dcl.init]:
 
@@ -298,7 +306,7 @@ build_default_init (type)
       
   /* At this point, TYPE is either a POD class type, an array of POD
      classes, or something even more inoccuous.  */
-  return build_zero_init (type, /*static_storage_p=*/false);
+  return build_zero_init (type, nelts, /*static_storage_p=*/false);
 }
 
 /* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of
@@ -364,7 +372,7 @@ perform_member_init (tree member, tree init)
        {
          if (explicit)
            {
-             init = build_default_init (type);
+             init = build_default_init (type, /*nelts=*/NULL_TREE);
              if (TREE_CODE (type) == REFERENCE_TYPE)
                warning
                  ("default-initialization of `%#D', which has reference type",
@@ -2367,7 +2375,7 @@ build_new_1 (exp)
       init_expr = build_indirect_ref (alloc_node, NULL);
 
       if (init == void_zero_node)
-       init = build_default_init (full_type);
+       init = build_default_init (full_type, nelts);
       else if (init && pedantic && has_array)
        pedwarn ("ISO C++ forbids initialization in array new");
 
index 5758bf4ae2fdb202b23f9c56457fb76bc975b91e..a4558790bbb59bf7b819fb70a5eb31acf33f9453 100644 (file)
@@ -733,6 +733,7 @@ process_init_constructor (type, init, elts)
            }
          else if (! zero_init_p (TREE_TYPE (type)))
            next1 = build_zero_init (TREE_TYPE (type),
+                                    /*nelts=*/NULL_TREE,
                                     /*static_storage_p=*/false);
          else
            /* The default zero-initialization is fine for us; don't
@@ -851,6 +852,7 @@ process_init_constructor (type, init, elts)
 
              if (! zero_init_p (TREE_TYPE (field)))
                next1 = build_zero_init (TREE_TYPE (field),
+                                        /*nelts=*/NULL_TREE,
                                         /*static_storage_p=*/false);
              else
                /* The default zero-initialization is fine for us; don't
index 9c81c63d6f35718b963329dabc6227cd15aaf68b..ac2985ca824007f126f448d631068b794660fc4a 100644 (file)
@@ -1,3 +1,8 @@
+2003-02-28  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/9879
+       * testsuite/g++.dg/init/new4.C: New test.
+
 2003-02-28  Richard Earnshaw  <rearnsha@arm.com>
 
        * gcc.dg/arm-asm.c: Enable for StrongARM and XScale targets.
diff --git a/gcc/testsuite/g++.dg/init/new4.C b/gcc/testsuite/g++.dg/init/new4.C
new file mode 100644 (file)
index 0000000..ab2fe31
--- /dev/null
@@ -0,0 +1 @@
+int *x = new int [2] ();