diff mbox

C++ PATCH for c++/46293 (ICE with constexpr value-init of empty base)

Message ID 4CD2277E.3070006@redhat.com
State New
Headers show

Commit Message

Jason Merrill Nov. 4, 2010, 3:24 a.m. UTC
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.

Comments

Gabriel Dos Reis Nov. 4, 2010, 8:46 a.m. UTC | #1
On Wed, Nov 3, 2010 at 10:24 PM, Jason Merrill <jason@redhat.com> wrote:
> I already had code for initializing an empty base via a constructor call,
> but failed to handle value-initialization via a CONSTRUCTOR.

Thanks a lot Jason.  I suspect `constexpr' somehow asks for a more
systematic (and principled) representation at the front-end level.
That is job for another time though.

-- Gaby
H.J. Lu Jan. 7, 2011, 1:39 a.m. UTC | #2
On Wed, Nov 3, 2010 at 8:24 PM, Jason Merrill <jason@redhat.com> wrote:
> 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.
>

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47041
diff mbox

Patch

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{};