commit fc150101bb79b3b328263e272a44eecd1083e6cd
Author: Jason Merrill <jason@redhat.com>
Date: Thu Oct 13 21:57:21 2011 -0400
PR c++/50507
* method.c (walk_field_subobs): Check for NSDMI before
complaining about uninitialized fields.
@@ -1016,25 +1016,7 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
}
else if (sfk == sfk_constructor)
{
- bool bad = true;
- if (CP_TYPE_CONST_P (mem_type)
- && default_init_uninitialized_part (mem_type))
- {
- if (msg)
- error ("uninitialized non-static const member %q#D",
- field);
- }
- else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
- {
- if (msg)
- error ("uninitialized non-static reference member %q#D",
- field);
- }
- else
- bad = false;
-
- if (bad && deleted_p)
- *deleted_p = true;
+ bool bad;
if (DECL_INITIAL (field))
{
@@ -1057,6 +1039,26 @@ walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
continue;
}
+ bad = false;
+ if (CP_TYPE_CONST_P (mem_type)
+ && default_init_uninitialized_part (mem_type))
+ {
+ if (msg)
+ error ("uninitialized non-static const member %q#D",
+ field);
+ bad = true;
+ }
+ else if (TREE_CODE (mem_type) == REFERENCE_TYPE)
+ {
+ if (msg)
+ error ("uninitialized non-static reference member %q#D",
+ field);
+ bad = true;
+ }
+
+ if (bad && deleted_p)
+ *deleted_p = true;
+
/* For an implicitly-defined default constructor to be constexpr,
every member must have a user-provided default constructor or
an explicit initializer. */
new file mode 100644
@@ -0,0 +1,10 @@
+// PR c++/50707
+// { dg-options -std=c++0x }
+
+int g;
+
+struct S {
+ int const v=g;
+};
+
+S s;