re PR c++/58650 ([c++11] ICE with invalid friend declaration)
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 16 Dec 2014 23:28:31 +0000 (23:28 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 16 Dec 2014 23:28:31 +0000 (23:28 +0000)
/cp
2014-12-16  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/58650
* parser.c (cp_parser_member_declaration): Fix error recovery for
initialized non-static data member declared friend.

/testsuite
2014-12-16  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/58650
* g++.dg/parse/friend12.C: New.

From-SVN: r218801

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/friend12.C [new file with mode: 0644]

index 4c6043e24eb99758ba716b8bb6824369c4dc052b..42c0bb50db124648d5f9b948da0633d682610354 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-16  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/58650
+       * parser.c (cp_parser_member_declaration): Fix error recovery for
+       initialized non-static data member declared friend.
+
 2014-12-15  Jan Hubicka  <hubicka@ucw.cz>
 
        * decl2.c (decl_needed_p): When not optimizing, do not consider external
index 76725efde7d280fac2dc22d02f95522660c7db11..0e7ba7aa3af808fb2c56d3301d5c73d8194ee9a8 100644 (file)
@@ -21069,7 +21069,10 @@ cp_parser_member_declaration (cp_parser* parser)
          if (decl)
            {
              /* Add DECL to the list of members.  */
-             if (!friend_p)
+             if (!friend_p
+                 /* Explicitly include, eg, NSDMIs, for better error
+                    recovery (c++/58650).  */
+                 || !DECL_DECLARES_FUNCTION_P (decl))
                finish_member_declaration (decl);
 
              if (TREE_CODE (decl) == FUNCTION_DECL)
index 5f9d676d2afca4d5a4810c0543f2bdcca90e6ce3..e896b0b73ce145269b776b958423f81d6437ef3b 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-16  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/58650
+       * g++.dg/parse/friend12.C: New.
+
 2014-12-16  Oleg Endo  <olegendo@gcc.gnu.org>
 
        PR target/54089
diff --git a/gcc/testsuite/g++.dg/parse/friend12.C b/gcc/testsuite/g++.dg/parse/friend12.C
new file mode 100644 (file)
index 0000000..f0e28a8
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/58650
+
+struct A
+{
+  friend int i = 0;  // { dg-error "cannot be declared friend" }
+// { dg-error "non-static data member" "" { target { ! c++11 } } 5 }
+};