This is basically the same as c++/49924, but for classes instead of arrays: if there is no explicit initializer written in the init-list, the member is value-initialized.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.
commit eccc1f7f9987a394dcf9856d43244a95c51bc880
Author: Jason Merrill <ja...@redhat.com>
Date:   Tue Aug 30 10:28:05 2011 -0400

    	PR c++/50234
    	* semantics.c (cxx_eval_component_reference): Handle
    	value-initialization for omitted initializers.

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 07f53b5..1ad991f 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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.
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C
new file mode 100644
index 0000000..38d8993
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-value3.C
@@ -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);

Reply via email to