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
This commit is contained in:
Jason Merrill 2015-12-17 11:51:58 -05:00 committed by Jason Merrill
parent 6ef15591e3
commit 62f9ab0d43
3 changed files with 26 additions and 0 deletions

View file

@ -1,5 +1,9 @@
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.

View file

@ -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;

View file

@ -0,0 +1,17 @@
// 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();
}