re PR c++/50234 (internal compiler error: in cxx_eval_component_reference, at cp...
authorJason Merrill <jason@redhat.com>
Tue, 30 Aug 2011 15:28:30 +0000 (11:28 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 30 Aug 2011 15:28:30 +0000 (11:28 -0400)
PR c++/50234
* semantics.c (cxx_eval_component_reference): Handle
value-initialization for omitted initializers.

From-SVN: r178325

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C [new file with mode: 0644]

index 315078aad33e36b3751e455a9a0b0d7614d8fd3f..9abac29a151e3c19dcedca30d2efe36417db2b90 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-30  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50234
+       * semantics.c (cxx_eval_component_reference): Handle
+       value-initialization for omitted initializers.
+
 2011-08-29  Jason Merrill  <jason@redhat.com>
 
        PR c++/50224
index 07f53b5cd127b85140c5ae9d1830adbe5673f659..1ad991fab4e085801a7a6a61e88a3c6337114919 100644 (file)
@@ -6518,7 +6518,8 @@ cxx_eval_component_reference (const constexpr_call *call, tree t,
       if (field == part)
         return value;
     }
-  if (TREE_CODE (TREE_TYPE (whole)) == UNION_TYPE)
+  if (TREE_CODE (TREE_TYPE (whole)) == UNION_TYPE
+      && CONSTRUCTOR_NELTS (whole) > 0)
     {
       /* DR 1188 says we don't have to deal with this.  */
       if (!allow_non_constant)
@@ -6527,8 +6528,12 @@ cxx_eval_component_reference (const constexpr_call *call, tree t,
       *non_constant_p = true;
       return t;
     }
-  gcc_unreachable();
-  return error_mark_node;
+
+  /* If there's no explicit init for this field, it's value-initialized.  */
+  value = build_value_init (TREE_TYPE (t), tf_warning_or_error);
+  return cxx_eval_constant_expression (call, value,
+                                      allow_non_constant, addr,
+                                      non_constant_p);
 }
 
 /* Subroutine of cxx_eval_constant_expression.
index 2449a63ac63b7a5205c09ed5e13573945313a69d..237deac888c2a69df431c121f441fbb6c545f37a 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-30  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50234
+       * g++.dg/cpp0x/constexpr-value3.C: New.
+
 2011-08-30  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/48571
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C
new file mode 100644 (file)
index 0000000..38d8993
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/50234
+// { dg-options -std=c++0x }
+
+#define SA(X) static_assert((X),#X)
+
+struct A { int i; };
+
+constexpr int f(A a) { return a.i; }
+
+SA(f({}) == 0);