From c2236b9b79e38e853026ac236984fcb5eabfb5df Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 26 Feb 2018 22:52:39 +0100 Subject: [PATCH] re PR c++/84558 (ICE with invalid constexpr constructor) PR c++/84558 * constexpr.c (cxx_eval_vec_init_1): For reuse, treat NULL eltinit like a valid constant initializer. Formatting fixes. * g++.dg/cpp1y/pr84558.C: New test. From-SVN: r258014 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 14 +++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1y/pr84558.C | 6 ++++++ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/pr84558.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d75f1a834e6..14f899c1881 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-26 Jakub Jelinek + + PR c++/84558 + * constexpr.c (cxx_eval_vec_init_1): For reuse, treat NULL eltinit like + a valid constant initializer. Formatting fixes. + 2018-02-26 Paolo Carlini PR c++/84540 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 26d0d099a05..b3de62a5bea 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2959,9 +2959,8 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, if (!lvalue_p (init)) eltinit = move (eltinit); eltinit = force_rvalue (eltinit, tf_warning_or_error); - eltinit = (cxx_eval_constant_expression - (&new_ctx, eltinit, lval, - non_constant_p, overflow_p)); + eltinit = cxx_eval_constant_expression (&new_ctx, eltinit, lval, + non_constant_p, overflow_p); } if (*non_constant_p && !ctx->quiet) break; @@ -2974,12 +2973,13 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init, else CONSTRUCTOR_APPEND_ELT (*p, idx, eltinit); /* Reuse the result of cxx_eval_constant_expression call - from the first iteration to all others if it is a constant - initializer that doesn't require relocations. */ + from the first iteration to all others if it is a constant + initializer that doesn't require relocations. */ if (reuse && max > 1 - && (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit)) - == null_pointer_node)) + && (eltinit == NULL_TREE + || (initializer_constant_valid_p (eltinit, TREE_TYPE (eltinit)) + == null_pointer_node))) { if (new_ctx.ctor != ctx->ctor) eltinit = new_ctx.ctor; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f050086b8bb..11d79943b9c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-26 Jakub Jelinek + + PR c++/84558 + * g++.dg/cpp1y/pr84558.C: New test. + 2018-02-26 Paolo Carlini PR c++/84540 diff --git a/gcc/testsuite/g++.dg/cpp1y/pr84558.C b/gcc/testsuite/g++.dg/cpp1y/pr84558.C new file mode 100644 index 00000000000..40d7ef68561 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr84558.C @@ -0,0 +1,6 @@ +// PR c++/84558 +// { dg-do compile { target c++14 } } + +struct A { static int i; constexpr A () { i = 0; } }; +struct B { A a[2][3][4]; }; +B b; -- 2.30.2