On Thu, Mar 10, 2016 at 06:37:32PM +0100, Jakub Jelinek wrote: > On Thu, Mar 10, 2016 at 12:34:40PM -0500, Patrick Palka wrote: > > Doesn't this mean that we call initializer_constant_valid_p at each > > iteration? This would slow down the non-constant case even further. > > So I wonder if the return value of initializer_constant_valid_p could > > be cached or something, since it seems like a potentially expensive > > predicate. > > You're right, but I've already committed the patch. I'll write an > incremental patch and test it.
So, like this? 2016-03-10 Jakub Jelinek <ja...@redhat.com> PR c++/70001 * constexpr.c (cxx_eval_vec_init_1): For pre_init, only call initializer_constant_valid_p on the first iteration. --- gcc/cp/constexpr.c.jj 2016-03-10 12:52:04.000000000 +0100 +++ gcc/cp/constexpr.c 2016-03-10 18:45:13.416533853 +0100 @@ -2391,17 +2391,21 @@ cxx_eval_vec_init_1 (const constexpr_ctx /* Initializing an element using value or default initialization we just pre-built above. */ if (pre_init_elt == NULL_TREE) - pre_init_elt - = cxx_eval_constant_expression (&new_ctx, init, lval, - non_constant_p, overflow_p); - eltinit = pre_init_elt; - /* Don't reuse the result of cxx_eval_constant_expression - call if it isn't a constant initializer or if it requires - relocations. */ - if (initializer_constant_valid_p (pre_init_elt, - TREE_TYPE (pre_init_elt)) - != null_pointer_node) - pre_init_elt = NULL_TREE; + { + eltinit + = cxx_eval_constant_expression (&new_ctx, init, lval, + non_constant_p, overflow_p); + /* Don't reuse the result of cxx_eval_constant_expression + call if it isn't a constant initializer or if it requires + relocations. */ + if (i == 0 + && (initializer_constant_valid_p (eltinit, + TREE_TYPE (eltinit)) + == null_pointer_node)) + pre_init_elt = eltinit; + } + else + eltinit = pre_init_elt; } else { Jakub