Patchwork RFA: PATCH to constructor_static_from_elts_p

login
register
mail settings
Submitter Jason Merrill
Date Aug. 6, 2010, 8:18 p.m.
Message ID <4C5C6E15.6040207@redhat.com>
Download mbox | patch
Permalink /patch/61153/
State New
Headers show

Comments

Jason Merrill - Aug. 6, 2010, 8:18 p.m.
Working on the C++0x constexpr branch, I noticed that 
initializer_constant_valid_p was returning false for CONSTRUCTORs of 
ARRAY_TYPE and ones with no elements.

The second restriction went in in r11333, and seems to have just been to 
avoid an ICE on dereferencing NULL, which is now irrelevant.

The type restriction seems to be a holdover from when RMS first added 
this code in r5921 in order to handle a special case of union casting. 
Now the code is much more general, and there doesn't seem to be any 
justification for retaining this restriction.

Tested x86_64-pc-linux-gnu.  OK for trunk now?  OK for trunk when I 
merge the constexpr branch?

Patch

commit f978e83eff0078e22bb702596286c708b5eb5e03
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 6 20:09:38 2010 +0200

    	* varasm.c (constructor_static_from_elts_p): Don't require a
    	CONSTRUCTOR to have elements to be suitable for static
    	initialization.  Allow ARRAY_TYPE as well.

diff --git a/gcc/varasm.c b/gcc/varasm.c
index 4742304..d85e2bb 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -3893,8 +3893,8 @@  constructor_static_from_elts_p (const_tree ctor)
 {
   return (TREE_CONSTANT (ctor)
 	  && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
-	      || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
-	  && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
+	      || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
+	      || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
 }
 
 static tree initializer_constant_valid_p_1 (tree value, tree endtype,