This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch][c++/PR 31743]
Mark Mitchell wrote:
Dave Brolley wrote:
I tried this and it yields the inaccurate diagnostic
31743.C:2: error: cannot convert ‘int*’ to ‘int (*)[]’ in initialization
The problem is that require_complete_type expects an *expression* but
the tree we have in build_new represents a *type*.
Excellent point. In that context, then, one should do:
if (!complete_type_or_else(type, NULL_TREE))
return error_mark_node;
That routine is explicitly for the case where you may not have a value.
Does using that work better?
Yes, this works. It also removes the need to call complete_type_or_else
at all in build_new_1. So, here's my latest patch, ChangeLog and test
case. The patch fixes the problem and causes no regressions in the test
suite.
Dave
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.
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (revision 125888)
+++ gcc/cp/init.c (working copy)
@@ -1704,9 +1704,6 @@
}
}
- 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;
@@ -2209,6 +2206,10 @@
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: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c (revision 125888)
+++ gcc/cp/parser.c (working copy)
@@ -5521,11 +5521,6 @@
}
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;
}
// PR c++/31743
typedef int A[];
A* p = new A; // { dg-error "invalid use of array with unspecified bounds" }
A* q = new (A); // { dg-error "invalid use of array with unspecified bounds" }