diff mbox

C++ PATCH for c++/50507 (NSDMI for const field)

Message ID 4E987800.1090107@redhat.com
State New
Headers show

Commit Message

Jason Merrill Oct. 14, 2011, 5:57 p.m. UTC
We should check for an initializer before complaining about lack 
thereof.  :)

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

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.

diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index f4a3ea6..0718f47 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -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.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C
new file mode 100644
index 0000000..ddf9f04
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-const1.C
@@ -0,0 +1,10 @@ 
+// PR c++/50707
+// { dg-options -std=c++0x }
+
+int g;
+
+struct S {
+   int const v=g;
+};
+
+S s;