From patchwork Wed Oct 17 16:05:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [C++] PR 54501 From: Paolo Carlini X-Patchwork-Id: 192082 Message-Id: <507ED72D.7080403@oracle.com> To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill Date: Wed, 17 Oct 2012 18:05:01 +0200 ... oh well, I just realized that zero-size VECTORs don't make much sense and are early rejected, thus I can improve my earlier patch. Now I'm happier: essentially I'm only *moving* code around ;) Thanks, Paolo. ////////////////////// /cp 2012-10-17 Paolo Carlini PR c++/54501 * decl.c (reshape_init_array): Check for zero-size arrays. (reshape_init_array_1): Don't handle zero-size arrays here. /testsuite 2012-10-17 Paolo Carlini PR c++/54501 * g++.dg/init/array30.C: New. * g++.dg/init/array0.C: Adjust. * g++.dg/parse/pr43765.C: Likewise. Index: cp/decl.c =================================================================== --- cp/decl.c (revision 192527) +++ cp/decl.c (working copy) @@ -5022,10 +5022,6 @@ reshape_init_array_1 (tree elt_type, tree max_inde if (sized_array_p) { - /* Minus 1 is used for zero sized arrays. */ - if (integer_all_onesp (max_index)) - return new_init; - if (host_integerp (max_index, 1)) max_index_cst = tree_low_cst (max_index, 1); /* sizetype is sign extended, not zero extended. */ @@ -5068,6 +5064,14 @@ reshape_init_array (tree type, reshape_iter *d, ts if (TYPE_DOMAIN (type)) max_index = array_type_nelts (type); + /* Minus 1 is used for zero sized arrays. */ + if (max_index && integer_all_onesp (max_index)) + { + if (complain & tf_error) + error ("initializers provided for zero-size array of type %qT", type); + return error_mark_node; + } + return reshape_init_array_1 (TREE_TYPE (type), max_index, d, complain); } Index: testsuite/g++.dg/parse/pr43765.C =================================================================== --- testsuite/g++.dg/parse/pr43765.C (revision 192527) +++ testsuite/g++.dg/parse/pr43765.C (working copy) @@ -11,4 +11,4 @@ SomeType vals[] = { { values : temp, }, 0 - }; // { dg-error "invalid" } + }; // { dg-error "zero-size" } Index: testsuite/g++.dg/init/array30.C =================================================================== --- testsuite/g++.dg/init/array30.C (revision 0) +++ testsuite/g++.dg/init/array30.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/54501 +// { dg-options "" } + +int main() +{ + int a[][0] = {0}; // { dg-error "zero-size" } +} Index: testsuite/g++.dg/init/array0.C =================================================================== --- testsuite/g++.dg/init/array0.C (revision 192527) +++ testsuite/g++.dg/init/array0.C (working copy) @@ -8,5 +8,5 @@ void foo() unsigned char dir; int data[0]; } yanito; - static const yanito horse = { 1, { 2, 3 } }; // { dg-error "too many" } + static const yanito horse = { 1, { 2, 3 } }; // { dg-error "zero-size" } }