Commit 62f9ab0d by Jason Merrill Committed by Jason Merrill

re PR c++/67550 (Initialization of local struct array with elements of global…

re PR c++/67550 (Initialization of local struct array with elements of global array yields zeros instead of initializer values)

	PR c++/67550

	* init.c (constant_value_1): Don't return a CONSTRUCTOR missing
	non-constant elements.

From-SVN: r231777
parent 6ef15591
2015-12-17 Jason Merrill <jason@redhat.com>
PR c++/67550
* init.c (constant_value_1): Don't return a CONSTRUCTOR missing
non-constant elements.
PR c++/67576
PR c++/25466
* rtti.c (build_typeid): Use save_expr, not stabilize_reference.
......
......@@ -2093,6 +2093,11 @@ constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
&& (TREE_CODE (init) == CONSTRUCTOR
|| TREE_CODE (init) == STRING_CST)))
break;
/* Don't return a CONSTRUCTOR for a variable with partial run-time
initialization, since it doesn't represent the entire value. */
if (TREE_CODE (init) == CONSTRUCTOR
&& !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
break;
decl = unshare_expr (init);
}
return decl;
......
// PR c++/67550
// { dg-do run }
struct S {
int x;
int y;
};
int foo() { return 1; }
int main() {
S const data[] = {{0, foo()}};
S data2[] = {data[0]};
if (!data2[0].y)
__builtin_abort();
}
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