]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/68585 (c++14 code accepted by 4.9 not accepted by 5 and 6)
authorJason Merrill <jason@redhat.com>
Thu, 18 Feb 2016 05:08:02 +0000 (00:08 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 18 Feb 2016 05:08:02 +0000 (00:08 -0500)
PR c++/68585
* constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection.

From-SVN: r233513

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C [new file with mode: 0644]

index c560375a5e515e0568baed3b30ff87a5169d75d3..963ba5a5644e08884d1a2e0ccfb198af6dddf677 100644 (file)
@@ -1,5 +1,8 @@
 2016-02-17  Jason Merrill  <jason@redhat.com>
 
+       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.
 
index 11037fb62ca7bc88d6448ce10e5855412c74ed17..0eedfca6663af5a210038055f98250668ca1b462 100644 (file)
@@ -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 (file)
index 0000000..239b91e
--- /dev/null
@@ -0,0 +1,41 @@
+// PR c++/68585
+// { dg-do compile { target c++11 } }
+
+template<typename T, unsigned N>
+  struct array
+  {
+    T _M_data[N];
+  };
+
+template<typename _Tp, _Tp... _Idx>
+  struct integer_sequence
+  {
+  };
+
+struct Pos
+{
+  unsigned l;
+};
+
+template<class T, T... Ints>
+constexpr array<Pos, sizeof...(Ints)> make_grid_position(integer_sequence<T, Ints...>)
+{
+  return {{ Pos{Ints}... }};
+}
+
+constexpr array<Pos, 1> make_grid_positions()
+{
+  return make_grid_position(integer_sequence<unsigned, 0>{});
+}
+
+template<class T>
+void generate_sudoku(T)
+{
+  constexpr auto positions = make_grid_positions(); // fail
+}
+
+int main()
+{
+  constexpr auto positions = make_grid_positions(); // ok
+  generate_sudoku(1);
+}