------- Comment #5 from brolley at redhat dot com 2007-06-08 15:41 ------- OK, I've looked into this a bit more. For inspiration I looked into where the error is generated when an incomplete struct is used instead of an unsized array. I found it in:
cxx_incomplete_type_diagnostic called by complete_type_or_else called by build_new_1 I also discovered that this sequence of calls should have detected an unsized array and generated the message we want. The reason it didn't is because this knowledge is forgotten in cp_parser_new_type_id (in the case of "new A") or in build_new_1 (in the case of "new (A)") when the top level array bound is stripped off. This is done (in both cases) before complete_type_or_else is called. Now, the transformation in cp_parser_new_type_id is unnecessary since the same transformation is done in build_new_1 and (as noted above) it is not performed in the case of "new (A)". This gives us the opportunity to generate the error in build_new_1 by calling complete_type_or_else before the transformation. I'm attaching a patch which implements these two changes. The patch generates the error "31743.C:2: error: invalid use of array with unspecified bounds" which is analogous to the message generated when an incomplete struct is used. Andrew's patch is not necessary for the generation of the error, but it makes sense to punt early in array_type_nelts_top when dealing with error_mark_node regardless. Tested against the trunk with no regressions in "make check-gcc". -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31743