* constexpr.c (cxx_eval_vec_init_1): For pre_init case, reuse
return value from cxx_eval_constant_expression from earlier
elements if it is valid constant initializer requiring no
relocations.
* g++.dg/cpp0x/constexpr-70001-1.C: New test.
* g++.dg/cpp0x/constexpr-70001-2.C: New test.
* g++.dg/cpp0x/constexpr-70001-3.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234117
138bc75d-0d04-0410-961f-
82ee72b054a4
+2016-03-10 Patrick Palka <ppalka@gcc.gnu.org>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/70001
+ * constexpr.c (cxx_eval_vec_init_1): For pre_init case, reuse
+ return value from cxx_eval_constant_expression from earlier
+ elements if it is valid constant initializer requiring no
+ relocations.
+
2016-03-10 Marek Polacek <polacek@redhat.com>
PR c++/70153
vec<constructor_elt, va_gc> **p = &CONSTRUCTOR_ELTS (ctx->ctor);
vec_alloc (*p, max + 1);
bool pre_init = false;
+ tree pre_init_elt = NULL_TREE;
unsigned HOST_WIDE_INT i;
/* For the default constructor, build up a call to the default
{
/* Initializing an element using value or default initialization
we just pre-built above. */
- eltinit = (cxx_eval_constant_expression
- (&new_ctx, init,
- lval, non_constant_p, overflow_p));
+ if (pre_init_elt == NULL_TREE)
+ pre_init_elt
+ = cxx_eval_constant_expression (&new_ctx, init, lval,
+ non_constant_p, overflow_p);
+ eltinit = pre_init_elt;
+ /* Don't reuse the result of cxx_eval_constant_expression
+ call if it isn't a constant initializer or if it requires
+ relocations. */
+ if (initializer_constant_valid_p (pre_init_elt,
+ TREE_TYPE (pre_init_elt))
+ != null_pointer_node)
+ pre_init_elt = NULL_TREE;
}
else
{
+2016-03-10 Patrick Palka <ppalka@gcc.gnu.org>
+ Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/70001
+ * g++.dg/cpp0x/constexpr-70001-1.C: New test.
+ * g++.dg/cpp0x/constexpr-70001-2.C: New test.
+ * g++.dg/cpp0x/constexpr-70001-3.C: New test.
+
2016-03-10 Jan Hubicka <hubicka@ucw.cz>
PR lto/69589
--- /dev/null
+// PR c++/70001
+// { dg-do compile { target c++11 } }
+
+struct B
+{
+ int a;
+ constexpr B () : a (0) { }
+};
+
+struct A
+{
+ B b[1 << 19];
+} c;
--- /dev/null
+// PR c++/70001
+// { dg-do run { target c++11 } }
+
+struct B
+{
+ struct B *a;
+ constexpr B () : a (this) { }
+};
+
+constexpr int N = 1 << 4;
+struct A { B c[N]; } d;
+
+int
+main ()
+{
+ for (int i = 0; i < N; ++i)
+ if (d.c[i].a != &d.c[i])
+ __builtin_abort ();
+}
--- /dev/null
+// PR c++/70001
+// { dg-do compile { target c++11 } }
+
+#include <array>
+#include <complex>
+
+typedef std::complex<double> cd;
+
+const int LOG = 17;
+const int N = (1 << LOG);
+
+std::array<cd, N> a;
+std::array<cd, N> b;
+
+void
+foo (std::array<cd, N> &arr)
+{
+ std::array<std::array<cd, N>, LOG + 1> f;
+}
+
+int
+main ()
+{
+ foo (a);
+ foo (b);
+}