From: jason Date: Thu, 17 Dec 2015 16:51:58 +0000 (+0000) Subject: PR c++/67550 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02df6497f638f375402643092f183d9c07ac0bfb;p=thirdparty%2Fgcc.git PR c++/67550 * init.c (constant_value_1): Don't return a CONSTRUCTOR missing non-constant elements. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231777 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 73906f3cb12b..4c7dc78a1972 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-12-17 Jason Merrill + 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. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index a08f7d70b258..b7f10a10e675 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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; diff --git a/gcc/testsuite/g++.dg/init/aggr13.C b/gcc/testsuite/g++.dg/init/aggr13.C new file mode 100644 index 000000000000..08248a6df946 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/aggr13.C @@ -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(); +}