This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/68585 (wrong error with constexpr list-initialization)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 18 Feb 2016 00:05:05 -0500
- Subject: C++ PATCH for c++/68585 (wrong error with constexpr list-initialization)
- Authentication-results: sourceware.org; auth=none
init_subob_ctx changed value, and then evaluating value didn't change
it, so we were thinking nothing had changed. Fixed by remembering the
value from before init_subob_ctx.
Tested x86_64-pc-linux-gnu, applying to trunk and 5.
commit afc049e2b450d7cccc10e62e3c0112e30a9600d6
Author: Jason Merrill <jason@redhat.com>
Date: Wed Feb 17 16:20:00 2016 -0500
PR c++/68585
* constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 11037fb..0eedfca 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 0000000..239b91e
--- /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<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);
+}