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 for c++/46293 (ICE with constexpr value-init of empty base)


I already had code for initializing an empty base via a constructor call, but failed to handle value-initialization via a CONSTRUCTOR.

Tested x86_64-pc-linux-gnu, applied to trunk.
commit ca941d88b6d0fd9c31941f24bf27589d7ee638b9
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 3 20:12:19 2010 -0400

    	PR c++/46293
    	* semantics.c (build_data_member_initialization): Handle
    	value-init of aggregate empty base.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 562fab1..9061a89 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5460,6 +5460,14 @@ build_data_member_initialization (tree t, VEC(constructor_elt,gc) **vec)
     {
       member = TREE_OPERAND (t, 0);
       init = unshare_expr (TREE_OPERAND (t, 1));
+      if (TREE_CODE (member) == INDIRECT_REF)
+	{
+	  /* Don't put out anything for value-init of an empty base.  */
+	  gcc_assert (is_empty_class (TREE_TYPE (member)));
+	  gcc_assert (TREE_CODE (init) == CONSTRUCTOR
+		      && CONSTRUCTOR_NELTS (init) == 0);
+	  return true;
+	}
     }
   else
     {
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base2.C
new file mode 100644
index 0000000..3ea7543
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base2.C
@@ -0,0 +1,19 @@
+// PR c++/46293
+// { dg-options -std=c++0x }
+
+struct A
+{
+};
+
+struct C
+{
+  int i;
+  constexpr C(int i): i(i) {}
+};
+
+struct B: A, C
+{
+  constexpr B(): A(), C(42) { }
+};
+
+constexpr B b{};

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