@@ -2573,6 +2573,7 @@ def _parse_type(
25732573
25742574 pqname : typing .Optional [PQName ] = None
25752575 pqname_optional = False
2576+ friend_tok : typing .Optional [LexToken ] = None
25762577
25772578 _pqname_start_tokens = self ._pqname_start_tokens
25782579 _attribute_start = self ._attribute_start_tokens
@@ -2597,6 +2598,8 @@ def _parse_type(
25972598 break
25982599 elif tok_type == "const" :
25992600 const = True
2601+ elif tok_type == "friend" and pqname is None :
2602+ friend_tok = tok
26002603 elif tok_type in self ._type_kwd_both :
26012604 if tok_type == "extern" :
26022605 # TODO: store linkage
@@ -2635,7 +2638,7 @@ def _parse_type(
26352638 self .lex .return_token (tok )
26362639
26372640 # Always return the modifiers
2638- mods = ParsedTypeModifiers (vars , both , meths , explicit_value )
2641+ mods = ParsedTypeModifiers (vars , both , meths , explicit_value , friend_tok )
26392642 return parsed_type , mods
26402643
26412644 def _parse_decl (
@@ -2871,6 +2874,12 @@ def _parse_declarations(
28712874 parsed_type , mods = self ._parse_type (tok , operator_ok = True )
28722875 attributes .extend (self ._take_pending_attributes ())
28732876
2877+ if mods .friend is not None :
2878+ if is_friend or is_typedef or not isinstance (self .state , ClassBlockState ):
2879+ raise self ._parse_error (mods .friend )
2880+ is_friend = True
2881+ mods = mods ._replace (friend = None )
2882+
28742883 # Check to see if this might be a class/enum declaration
28752884 if (
28762885 parsed_type is not None
0 commit comments