diff mbox

C++ PATCH for NSDMI that depends on itself

Message ID 4F52BD88.9070607@redhat.com
State New
Headers show

Commit Message

Jason Merrill March 4, 2012, 12:55 a.m. UTC
While thinking about core issue 1351, I noticed that we weren't dealing 
very well with an NSDMI that depends on itself.  This patch gives a 
helpful error message.

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

Patch

commit 46131bcba27d82f43a26daa12a8c8e95f7208696
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Feb 20 06:15:24 2012 -0500

    	* init.c (perform_member_init): Cope with uninstantiated NSDMI.

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 2355a04..1b2a1ef 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -540,6 +540,12 @@  perform_member_init (tree member, tree init)
       else
 	{
 	  init = DECL_INITIAL (member);
+	  if (init && TREE_CODE (init) == DEFAULT_ARG)
+	    {
+	      error ("constructor required before non-static data member "
+		     "for %qD has been parsed", member);
+	      init = NULL_TREE;
+	    }
 	  /* Strip redundant TARGET_EXPR so we don't need to remap it, and
 	     so the aggregate init code below will see a CONSTRUCTOR.  */
 	  if (init && TREE_CODE (init) == TARGET_EXPR
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer6.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer6.C
new file mode 100644
index 0000000..033c142
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-defer6.C
@@ -0,0 +1,8 @@ 
+// { dg-do compile { target c++11 } }
+
+struct A			// { dg-error "non-static data member" }
+{
+  int i = (A(), 42);		// { dg-message "required here" }
+};
+
+A a;