diff mbox

[C++] PR 58650

Message ID 5490920D.7070405@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Dec. 16, 2014, 8:11 p.m. UTC
Hi,

On 12/16/2014 07:18 PM, Jason Merrill wrote:
> On 12/16/2014 12:49 PM, Paolo Carlini wrote:
>> I see what you mean: try to somehow realize that grokdeclarator issued
>> an error and we are in error recovery. What about directly addressing
>> NSDMIs, the specific case at issue, thus the below? A bit ad-hoc-ish but
>> on the other hand should be lighter than calling function_declarator_p,
>> etc, to figure out...
>
> Well, since only functions can be friends at this point, since types 
> take a different path, maybe change the if (!friend_p) just above to
> if (!friend_p || TREE_CODE (decl) != FUNCTION_DECL)?
Indeed, should have figured it out myself. Thanks. That also addresses 
my consistency concerns. Minor detail: I think we want 
DECL_DECLARES_FUNCTION_P to include templates, otherwise we regress on, 
eg, pr60390.C. I'm finishing testing the below.

Thanks again,
Paolo.

/////////////////////////

Comments

Jason Merrill Dec. 16, 2014, 10:08 p.m. UTC | #1
OK, thanks.

Jason
diff mbox

Patch

Index: cp/parser.c
===================================================================
--- cp/parser.c	(revision 218777)
+++ cp/parser.c	(working copy)
@@ -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: testsuite/g++.dg/parse/friend12.C
===================================================================
--- testsuite/g++.dg/parse/friend12.C	(revision 0)
+++ testsuite/g++.dg/parse/friend12.C	(working copy)
@@ -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 }
+};