This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] PR c++/87075 - ICE with constexpr array initialization.


My patch of 2016-08-26 to avoid calling a trivial default constructor
introduced TARGET_EXPRs initialized with void_node to express trivial
initialization.  But when this shows up in a VEC_INIT_EXPR, we weren't
prepared to handle it.  Fixed by handling it explicitly in
cxx_eval_vec_init_1.

Tested x86_64-pc-linux-gnu, applying to trunk, and later 7 and 8.

	* constexpr.c (cxx_eval_vec_init_1): Handle trivial initialization.
---
 gcc/cp/constexpr.c                            |  3 +++
 gcc/testsuite/g++.dg/cpp1y/constexpr-array6.C | 26 +++++++++++++++++++
 gcc/cp/ChangeLog                              |  5 ++++
 3 files changed, 34 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-array6.C

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index aa33319875f..fdea769faa9 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3034,6 +3034,9 @@ cxx_eval_vec_init_1 (const constexpr_ctx *ctx, tree atype, tree init,
 	{
 	  /* Initializing an element using value or default initialization
 	     we just pre-built above.  */
+	  if (init == void_node)
+	    /* Trivial default-init, don't do anything to the CONSTRUCTOR.  */
+	    return ctx->ctor;
 	  eltinit = cxx_eval_constant_expression (&new_ctx, init, lval,
 						  non_constant_p, overflow_p);
 	  reuse = i == 0;
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-array6.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-array6.C
new file mode 100644
index 00000000000..1f15bef8d0c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-array6.C
@@ -0,0 +1,26 @@
+// PR c++/87075
+// { dg-do compile { target c++14 } }
+
+template <typename T>
+struct vec
+{
+  struct { T y; } n;
+  vec() = default;
+};
+
+template <typename T>
+struct S
+{
+  vec<T> value[2];
+  template<typename U>
+  constexpr S(const U&);
+};
+
+template<typename T>
+template<typename X>
+constexpr S<T>::S(const X&)
+{
+  value[0] = vec<T>();
+}
+
+S<float>m(0);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 75286d53fdb..c5072d53334 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2018-09-20  Jason Merrill  <jason@redhat.com>
+
+	PR c++/87075 - ICE with constexpr array initialization.
+	* constexpr.c (cxx_eval_vec_init_1): Handle trivial initialization.
+
 2018-09-19  Marek Polacek  <polacek@redhat.com>
 
 	Add -Wclass-conversion.

base-commit: 51481b252ffe30a1daea491f62c687333efabc40
-- 
2.17.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]