public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] PR 54501
@ 2012-10-17 17:01 Paolo Carlini
  2012-10-17 17:27 ` Paolo Carlini
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Carlini @ 2012-10-17 17:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

Hi,

for this kind of code, using the GNU zero-size array extension:

   int a[][0] = {0};

we end up looping forever in the reshape_init_array_1 loop because it 
calls reshape_init_r -> reshape_init_array -> reshape_init_array_1 which 
returns early a CONSTRUCTOR with no error. Having considered various 
solutions, I'm proposing to break the endless loop in 
reshape_init_array, where we have information about the type of the 
zero-size array and we can easily provide an accurate error message.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////



[-- Attachment #2: CL_54501 --]
[-- Type: text/plain, Size: 315 bytes --]

/cp
2012-10-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54501
	* decl.c (reshape_init_array): Check for zero-size arrays.

/testsuite
2012-10-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54501
	* g++.dg/init/array30.C: New.
	* g++.dg/init/array0.C: Adjust.
	* g++.dg/parse/pr43765.C: Likewise.

[-- Attachment #3: patch_54501 --]
[-- Type: text/plain, Size: 1743 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 192527)
+++ cp/decl.c	(working copy)
@@ -5068,6 +5068,13 @@ reshape_init_array (tree type, reshape_iter *d, ts
   if (TYPE_DOMAIN (type))
     max_index = array_type_nelts (type);
 
+  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/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" }
 }
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/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" }

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-10-18 22:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-17 17:01 [C++ Patch] PR 54501 Paolo Carlini
2012-10-17 17:27 ` Paolo Carlini
2012-10-18  3:06   ` Jason Merrill
2012-10-18  9:17     ` Paolo Carlini
2012-10-18 16:21       ` Jason Merrill
2012-10-18 17:40         ` Paolo Carlini
2012-10-18 19:32         ` Paolo Carlini
2012-10-18 23:07           ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).