2012-01-02 Jason Merrill <jason@redhat.com>
+ DR 1359
+ PR c++/51675
+ * method.c (walk_field_subobs): Don't check for uninitialized
+ fields in a union.
+ (synthesized_method_walk): Check here.
+
DR 325
PR c++/51666
* parser.c (cp_parser_cache_defarg): Split out...
/* For an implicitly-defined default constructor to be constexpr,
every member must have a user-provided default constructor or
an explicit initializer. */
- if (constexpr_p && !CLASS_TYPE_P (mem_type))
+ if (constexpr_p && !CLASS_TYPE_P (mem_type)
+ && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
{
*constexpr_p = false;
if (msg)
resolution, so a constructor can be trivial even if it would otherwise
call a non-trivial constructor. */
if (expected_trivial
- && !diag
&& (!copy_arg_p || cxx_dialect < cxx0x))
{
if (constexpr_p && sfk == sfk_constructor)
- *constexpr_p = trivial_default_constructor_is_constexpr (ctype);
- return;
+ {
+ bool cx = trivial_default_constructor_is_constexpr (ctype);
+ *constexpr_p = cx;
+ if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
+ /* A trivial constructor doesn't have any NSDMI. */
+ inform (input_location, "defaulted default constructor does "
+ "not initialize any non-static data member");
+ }
+ if (!diag)
+ return;
}
++cp_unevaluated_operand;
--- /dev/null
+// PR c++/51675
+// { dg-options -std=c++0x }
+
+union foo
+{
+ int x = 0;
+ short y;
+
+ constexpr foo() = default;
+};
+
+union bar
+{
+ int x;
+ short y;
+
+ constexpr bar() = default; // { dg-error "constexpr" }
+};