@@ -1925,10 +1925,23 @@ def _parse_pqname(
19251925 break
19261926
19271927 # If no more segments, we're done
1928- if not self .lex .token_if ("DBL_COLON" ):
1928+ tok = self .lex .token_if ("DBL_COLON" )
1929+ if not tok :
1930+ break
1931+
1932+ next_tok = self ._next_token_must_be (
1933+ "NAME" , "operator" , "template" , "decltype"
1934+ )
1935+ if next_tok .type == "operator" and not fn_ok :
1936+ # Qualified conversion operators (for example,
1937+ # ``Foo::operator int()``) do not have a leading return type.
1938+ # When parsing what might be a type, stop before the operator
1939+ # so declaration parsing can consume the qualified operator as
1940+ # the function name and parse the conversion type separately.
1941+ self .lex .return_tokens ([tok , next_tok ])
19291942 break
19301943
1931- tok = self . _next_token_must_be ( "NAME" , "operator" , "template" , "decltype" )
1944+ tok = next_tok
19321945
19331946 pqname = PQName (segments , classkey , has_typename )
19341947
@@ -2898,6 +2911,7 @@ def _parse_operator_conversion(
28982911 is_typedef : bool ,
28992912 is_friend : bool ,
29002913 attributes : typing .List [Attribute ],
2914+ pqname : typing .Optional [PQName ] = None ,
29012915 ) -> None :
29022916 tok = self ._next_token_must_be ("operator" )
29032917
@@ -2918,8 +2932,11 @@ def _parse_operator_conversion(
29182932 self ._next_token_must_be ("(" )
29192933
29202934 # make our own pqname/op here
2921- segments : typing .List [PQNameSegment ] = [NameSpecifier ("operator" )]
2922- pqname = PQName (segments )
2935+ if pqname is None :
2936+ segments : typing .List [PQNameSegment ] = [NameSpecifier ("operator" )]
2937+ pqname = PQName (segments )
2938+ else :
2939+ pqname = PQName ([* pqname .segments , NameSpecifier ("operator" )])
29232940 op = "conversion"
29242941
29252942 if self ._parse_function (
@@ -3024,6 +3041,25 @@ def _parse_declarations(
30243041 )
30253042 return
30263043
3044+ qtok = self .lex .token_if ("DBL_COLON" )
3045+ if qtok :
3046+ otok = self .lex .token_if ("operator" )
3047+ if otok :
3048+ self .lex .return_tokens ([qtok , otok ])
3049+ self ._next_token_must_be ("DBL_COLON" )
3050+ self ._parse_operator_conversion (
3051+ mods ,
3052+ location ,
3053+ doxygen ,
3054+ template ,
3055+ is_typedef ,
3056+ is_friend ,
3057+ attributes ,
3058+ parsed_type .typename ,
3059+ )
3060+ return
3061+ self .lex .return_token (qtok )
3062+
30273063 # Ok, dealing with a variable or function/method
30283064 while True :
30293065 if self ._parse_decl (
0 commit comments