===================================================================
@@ -21077,8 +21077,16 @@ cp_parser_member_declaration (cp_parser* parser)
else if (TREE_CODE (decl) == FIELD_DECL
&& !DECL_C_BIT_FIELD (decl)
&& DECL_INITIAL (decl))
- /* Add DECL to the queue of NSDMI to be parsed later. */
- vec_safe_push (unparsed_nsdmis, decl);
+ {
+
+ if (friend_p)
+ /* Explicitly include NSDMIs for error recovery purposes:
+ avoid crashing later if one is wrongly declared friend
+ (c++/58650). */
+ finish_member_declaration (decl);
+ /* Add DECL to the queue of NSDMI to be parsed later. */
+ vec_safe_push (unparsed_nsdmis, decl);
+ }
}
if (assume_semicolon)
===================================================================
@@ -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 }
+};