]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/50707 ([C++0x] Non-static const data member initializer breaks default...
authorJason Merrill <jason@redhat.com>
Fri, 14 Oct 2011 19:12:45 +0000 (15:12 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 14 Oct 2011 19:12:45 +0000 (15:12 -0400)
PR c++/50507
* method.c (walk_field_subobs): Check for NSDMI before
complaining about uninitialized fields.

From-SVN: r180002

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C [new file with mode: 0644]

index 0edf96641f672c7777b6271e358ac3a13a6dd9df..b55e2947bc438eb1f44028ba7f2923a4e96e0c4a 100644 (file)
@@ -1,5 +1,9 @@
 2011-10-14  Jason Merrill  <jason@redhat.com>
 
+       PR c++/50507
+       * method.c (walk_field_subobs): Check for NSDMI before
+       complaining about uninitialized fields.
+
        * pt.c (tsubst_decl) [FIELD_DECL]: Use void_zero_node
        instead of error_mark_node as a placeholder.
 
index f4a3ea6ac99d9c2c234d77017d7e66e7e98b4790..0718f47d743e7d15ed3192e7294380ba5438a5f1 100644 (file)
@@ -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.  */
index 708f3fd78dc5ec552cfed2c2f8abf7740c0ff75a..80ef91c87f97935f691c95e52042366ef88cb4f6 100644 (file)
@@ -1,3 +1,8 @@
+2011-10-14  Jason Merrill  <jason@redhat.com>
+
+       PR c++/50507
+       * g++.dg/cpp0x/nsdmi-const1.C: New.
+
 2011-10-14  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/50570
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C
new file mode 100644 (file)
index 0000000..ddf9f04
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/50707
+// { dg-options -std=c++0x }
+
+int g;
+
+struct S {
+   int const v=g;
+};
+
+S s;