This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch for PR c++/28256 (4.1/4.2 regression) ICE on invalid code


This patch fixes an ICE that happens when initializing a scalar variable
to an empty list.  While fixing this I changed the error message that
you get when initializing a scalar variable to a list of 2 (or more)
values from one about "too many initializers" to one about "requires one
initializer".  This required tweaking the expected output in
g++.dg/init/brace2.C so I just added the empty initializer test to that
same testcase instead of creating a seperate test.

The error message change for multiple initializer values could be undone
if people don't like it but I thought it was a reasonable change to make
as part of fixing the ICE (checking for exactly one value instead of
just checking for zero values in the initalizer).

Tested on IA64 Linux.  OK to checkin?

Steve Ellcey
sje@cup.hp.com



2006-07-28  Steve Ellcey  <sje@cup.hp.com>

	PR c++/28256
	* decl.c (check_initializer): Check for 1 initializer on scalar types.

Index: decl.c
===================================================================
--- decl.c	(revision 115787)
+++ decl.c	(working copy)
@@ -4730,6 +4730,15 @@ check_initializer (tree decl, tree init,
       TREE_TYPE (decl) = error_mark_node;
       init = NULL_TREE;
     }
+  else if (!CP_AGGREGATE_TYPE_P (type)
+	   && init && TREE_CODE (init) == CONSTRUCTOR
+	   && BRACE_ENCLOSED_INITIALIZER_P (init)
+	   && VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)) != 1)
+    {
+      error ("scalar object %qD requires one element in initializer", decl);
+      TREE_TYPE (decl) = error_mark_node;
+      init = NULL_TREE;
+    }
 
   if (TREE_CODE (decl) == CONST_DECL)
     {
2006-07-28  Steve Ellcey  <sje@cup.hp.com>

	PR c++/28256
	* g++.dg/init/brace2.C: Change expected error message, add empty init.

Index: g++.dg/init/brace2.C
===================================================================
--- g++.dg/init/brace2.C	(revision 115787)
+++ g++.dg/init/brace2.C	(working copy)
@@ -3,6 +3,6 @@
 int x = { 2 };
 const char * y = { "hello" };
 int a = 2;
-int b = { 2,3 }; // { dg-error "too many initializers" }
+int b = { 2,3 }; // { dg-error "requires one element in initializer" }
 int c = { { 2 } } ; // { dg-error "braces around scalar initializer" }
-
+int d = {}; // { dg-error "requires one element in initializer" }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]