From 5b884e9400741569ee385f0de4590c1730aa600c Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 21 Oct 2019 20:51:43 +0200 Subject: [PATCH] re PR c++/92015 (internal compiler error: in cxx_eval_array_reference, at cp/constexpr.c:2568) PR c++/92015 * constexpr.c (cxx_eval_component_reference, cxx_eval_bit_field_ref): Use STRIP_ANY_LOCATION_WRAPPER on CONSTRUCTOR elts. * g++.dg/cpp0x/constexpr-92015.C: New test. From-SVN: r277267 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 6 +++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/constexpr-92015.C | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-92015.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f861fb3..593510f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-10-21 Jakub Jelinek + + PR c++/92015 + * constexpr.c (cxx_eval_component_reference, cxx_eval_bit_field_ref): + Use STRIP_ANY_LOCATION_WRAPPER on CONSTRUCTOR elts. + 2019-10-21 Marek Polacek PR c++/92062 - ODR-use ignored for static member of class template. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 46d41ec..60d4b9a 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2887,7 +2887,10 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t, : field == part) { if (value) - return value; + { + STRIP_ANY_LOCATION_WRAPPER (value); + return value; + } else /* We're in the middle of initializing it. */ break; @@ -2977,6 +2980,7 @@ cxx_eval_bit_field_ref (const constexpr_ctx *ctx, tree t, FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (whole), i, field, value) { tree bitpos = bit_position (field); + STRIP_ANY_LOCATION_WRAPPER (value); if (bitpos == start && DECL_SIZE (field) == TREE_OPERAND (t, 1)) return value; if (TREE_CODE (TREE_TYPE (field)) == INTEGER_TYPE diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ba280a1..3f4e6c5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-21 Jakub Jelinek + + PR c++/92015 + * g++.dg/cpp0x/constexpr-92015.C: New test. + 2019-10-21 Marek Polacek PR c++/92062 - ODR-use ignored for static member of class template. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-92015.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-92015.C new file mode 100644 index 0000000..60f288e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-92015.C @@ -0,0 +1,7 @@ +// PR c++/92015 +// { dg-do compile { target c++11 } } + +struct S1 { char c[6] {'h', 'e', 'l', 'l', 'o', 0}; }; +struct S2 { char c[6] = "hello"; }; +static_assert (S1{}.c[0] == 'h', ""); +static_assert (S2{}.c[0] == 'h', ""); -- 2.7.4