Here, my assertion that a CONSTRUCTOR should be empty when we start to
give it an initial value was forgetting about the case of classes with
non-user-defined constructors, where value-initialization first
zero-initializes, then calls the synthesized constructor.
Tested x86_64-pc-linux-gnu, applying to trunk and 5.
commit c87b2db1a8bff1394c5e607f8d470f5eed20193c
Author: Jason Merrill <ja...@redhat.com>
Date: Wed Feb 10 21:17:52 2016 -0500
PR c++/68990
* constexpr.c (verify_ctor_sanity): Remove CONSTRUCTOR_NELTS check.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 85fc64e..11037fb 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -2202,7 +2202,8 @@ verify_ctor_sanity (const constexpr_ctx *ctx, tree type)
gcc_assert (ctx->ctor);
gcc_assert (same_type_ignoring_top_level_qualifiers_p
(type, TREE_TYPE (ctx->ctor)));
- gcc_assert (CONSTRUCTOR_NELTS (ctx->ctor) == 0);
+ /* We used to check that ctx->ctor was empty, but that isn't the case when
+ the object is zero-initialized before calling the constructor. */
if (ctx->object)
gcc_assert (same_type_ignoring_top_level_qualifiers_p
(type, TREE_TYPE (ctx->object)));
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-value5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-value5.C
new file mode 100644
index 0000000..8c67174
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-value5.C
@@ -0,0 +1,18 @@
+// PR c++/68990
+// { dg-do compile { target c++11 } }
+
+class ptr;
+template <long _Nm> struct A { typedef ptr _Type[_Nm]; };
+template <long _Nm> struct B { typename A<_Nm>::_Type _M_elems; };
+template <long N> class FixedVector : B<N> {
+public:
+ typedef B<1> base;
+ constexpr FixedVector() : base(), size_() {}
+ char size_;
+};
+class ptr {
+public:
+ constexpr ptr() : px_(){};
+ int px_;
+};
+FixedVector<1> a;