Commit 06b76c7f by Jason Merrill Committed by Jason Merrill

re PR c++/57402 (ICE: in make_decl_rtl, at varasm.c:1147 when initializing variable-sized array)

	PR c++/57402
	* init.c (build_vec_init): Don't take shortcuts when initializing
	a VLA.

From-SVN: r200860
parent 9be2cb37
2013-07-09 Jason Merrill <jason@redhat.com> 2013-07-09 Jason Merrill <jason@redhat.com>
PR c++/57402
* init.c (build_vec_init): Don't take shortcuts when initializing
a VLA.
PR c++/57471 PR c++/57471
* parser.c (cp_parser_sizeof_pack): Clear parser scopes. * parser.c (cp_parser_sizeof_pack): Clear parser scopes.
......
...@@ -3332,6 +3332,7 @@ build_vec_init (tree base, tree maxindex, tree init, ...@@ -3332,6 +3332,7 @@ build_vec_init (tree base, tree maxindex, tree init,
if (init if (init
&& TREE_CODE (atype) == ARRAY_TYPE && TREE_CODE (atype) == ARRAY_TYPE
&& TREE_CONSTANT (maxindex)
&& (from_array == 2 && (from_array == 2
? (!CLASS_TYPE_P (inner_elt_type) ? (!CLASS_TYPE_P (inner_elt_type)
|| !TYPE_HAS_COMPLEX_COPY_ASSIGN (inner_elt_type)) || !TYPE_HAS_COMPLEX_COPY_ASSIGN (inner_elt_type))
...@@ -3452,6 +3453,7 @@ build_vec_init (tree base, tree maxindex, tree init, ...@@ -3452,6 +3453,7 @@ build_vec_init (tree base, tree maxindex, tree init,
tree field, elt; tree field, elt;
/* Should we try to create a constant initializer? */ /* Should we try to create a constant initializer? */
bool try_const = (TREE_CODE (atype) == ARRAY_TYPE bool try_const = (TREE_CODE (atype) == ARRAY_TYPE
&& TREE_CONSTANT (maxindex)
&& (literal_type_p (inner_elt_type) && (literal_type_p (inner_elt_type)
|| TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type))); || TYPE_HAS_CONSTEXPR_CTOR (inner_elt_type)));
/* If the constructor already has the array type, it's been through /* If the constructor already has the array type, it's been through
...@@ -3561,6 +3563,8 @@ build_vec_init (tree base, tree maxindex, tree init, ...@@ -3561,6 +3563,8 @@ build_vec_init (tree base, tree maxindex, tree init,
/* Clear out INIT so that we don't get confused below. */ /* Clear out INIT so that we don't get confused below. */
init = NULL_TREE; init = NULL_TREE;
/* Any elements without explicit initializers get {}. */
explicit_value_init_p = true;
} }
else if (from_array) else if (from_array)
{ {
......
// PR c++/57402
// { dg-options "-std=c++1y -pedantic-errors" }
int i = 2;
int main()
{
{
int a[i];
a[1] = 0xbeef;
}
{
int a[i] = { 1 };
if (a[1] != 0)
__builtin_abort ();
a[1] = 0xbeef;
}
{
int a[i] = { };
if (a[1] != 0)
__builtin_abort ();
a[1] = 0xbeef;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment