From: Jason Merrill Date: Thu, 18 Feb 2016 05:08:02 +0000 (-0500) Subject: re PR c++/68585 (c++14 code accepted by 4.9 not accepted by 5 and 6) X-Git-Tag: basepoints/gcc-7~886 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcb5f3c9f5aa8d3368e887b40f4ab1197afab59e;p=thirdparty%2Fgcc.git re PR c++/68585 (c++14 code accepted by 4.9 not accepted by 5 and 6) PR c++/68585 * constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection. From-SVN: r233513 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c560375a5e51..963ba5a5644e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2016-02-17 Jason Merrill + PR c++/68585 + * constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection. + PR c++/68679 * decl2.c (reset_type_linkage_2): Look through member templates. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 11037fb62ca7..0eedfca6663a 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2234,6 +2234,7 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, bool side_effects_p = false; FOR_EACH_CONSTRUCTOR_ELT (v, i, index, value) { + tree orig_value = value; constexpr_ctx new_ctx; init_subob_ctx (ctx, new_ctx, index, value); if (new_ctx.ctor != ctx->ctor) @@ -2246,7 +2247,7 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, /* Don't VERIFY_CONSTANT here. */ if (ctx->quiet && *non_constant_p) break; - if (elt != value) + if (elt != orig_value) changed = true; if (!TREE_CONSTANT (elt)) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C new file mode 100644 index 000000000000..239b91ed0145 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C @@ -0,0 +1,41 @@ +// PR c++/68585 +// { dg-do compile { target c++11 } } + +template + struct array + { + T _M_data[N]; + }; + +template + struct integer_sequence + { + }; + +struct Pos +{ + unsigned l; +}; + +template +constexpr array make_grid_position(integer_sequence) +{ + return {{ Pos{Ints}... }}; +} + +constexpr array make_grid_positions() +{ + return make_grid_position(integer_sequence{}); +} + +template +void generate_sudoku(T) +{ + constexpr auto positions = make_grid_positions(); // fail +} + +int main() +{ + constexpr auto positions = make_grid_positions(); // ok + generate_sudoku(1); +}