From 0007ff03b088aadc9623e17df257a3e2792d115e Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 16 Dec 2014 23:28:31 +0000 Subject: [PATCH] re PR c++/58650 ([c++11] ICE with invalid friend declaration) /cp 2014-12-16 Paolo Carlini 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 PR c++/58650 * g++.dg/parse/friend12.C: New. From-SVN: r218801 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 5 ++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/friend12.C | 7 +++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/friend12.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4c6043e24eb..42c0bb50db1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-12-16 Paolo Carlini + + 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 * decl2.c (decl_needed_p): When not optimizing, do not consider external diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 76725efde7d..0e7ba7aa3af 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5f9d676d2af..e896b0b73ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-12-16 Paolo Carlini + + PR c++/58650 + * g++.dg/parse/friend12.C: New. + 2014-12-16 Oleg Endo 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 index 00000000000..f0e28a8527a --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/friend12.C @@ -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 } +}; -- 2.30.2