re PR c++/31743 (ICE with invalid use of new)
authorDave Brolley <brolley@redhat.com>
Wed, 4 Jul 2007 00:21:33 +0000 (20:21 -0400)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Wed, 4 Jul 2007 00:21:33 +0000 (00:21 +0000)
PR c++/31743
* parser.c (cp_parser_new_type_id): Don't reduce a named array
type to its base type and number of elements here.
* init.c (build_new): Call complete_type_or_else to ensure that the
type is complete and to issue a diagnostic if it is not.
(build_new_1): Don't call complete_type_or_else here.

PR c++/31743
* g++.dg/init/new20.C: New test.

From-SVN: r126292

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/new20.C [new file with mode: 0755]

index 059631f..7316fbf 100644 (file)
@@ -1,3 +1,12 @@
+2007-06-29  Dave Brolley  <brolley@redhat.com>
+
+       PR c++/31743
+       * parser.c (cp_parser_new_type_id): Don't reduce a named array
+       type to its base type and number of elements here.
+       * init.c (build_new): Call complete_type_or_else to ensure that the
+       type is complete and to issue a diagnostic if it is not.
+       (build_new_1): Don't call complete_type_or_else here.
+
 2007-07-03  Richard Guenther  <rguenther@suse.de>
 
        PR c++/32609
index 3eb6d5d..1647bc0 100644 (file)
@@ -1705,9 +1705,6 @@ build_new_1 (tree placement, tree type, tree nelts, tree init,
        }
     }
 
-  if (!complete_type_or_else (type, NULL_TREE))
-    return error_mark_node;
-
   /* If our base type is an array, then make sure we know how many elements
      it has.  */
   for (elt_type = type;
@@ -2210,6 +2207,10 @@ build_new (tree placement, tree type, tree nelts, tree init,
       return error_mark_node;
     }
 
+  /* PR 31743: Make sure the array type has a known size.  */
+  if (!complete_type_or_else (type, NULL_TREE))
+    return error_mark_node;
+
   rval = build_new_1 (placement, type, nelts, init, use_global_new);
   if (rval == error_mark_node)
     return error_mark_node;
index d6e6204..ae970d6 100644 (file)
@@ -5521,11 +5521,6 @@ cp_parser_new_type_id (cp_parser* parser, tree *nelts)
     }
 
   type = groktypename (&type_specifier_seq, new_declarator);
-  if (TREE_CODE (type) == ARRAY_TYPE && *nelts == NULL_TREE)
-    {
-      *nelts = array_type_nelts_top (type);
-      type = TREE_TYPE (type);
-    }
   return type;
 }
 
index fc5dca3..97d5e2b 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-29  Dave Brolley  <brolley@redhat.com>
+
+       PR c++/31743
+       * g++.dg/init/new20.C: New test.
+
 2007-07-03  Christopher D. Rickett  <crickett@lanl.gov>
 
        PR fortran/32579
diff --git a/gcc/testsuite/g++.dg/init/new20.C b/gcc/testsuite/g++.dg/init/new20.C
new file mode 100755 (executable)
index 0000000..705c1be
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/31743\r
+typedef int A[];\r
+A* p = new A;   // { dg-error "invalid use of array with unspecified bounds" }\r
+A* q = new (A); // { dg-error "invalid use of array with unspecified bounds" }\r
+\r
+\r