@@ -608,11 +608,19 @@ def _parse_template_decl(self) -> TemplateDecl:
608
608
param = self ._parse_template_type_parameter (tok , None )
609
609
else :
610
610
param , _ = self ._parse_parameter (
611
- ptok , TemplateNonTypeParam , False , ">"
611
+ ptok ,
612
+ TemplateNonTypeParam ,
613
+ concept_ok = False ,
614
+ deduce_this_ok = False ,
615
+ end = ">" ,
612
616
)
613
617
else :
614
618
param , _ = self ._parse_parameter (
615
- tok , TemplateNonTypeParam , concept_ok = False , end = ">"
619
+ tok ,
620
+ TemplateNonTypeParam ,
621
+ concept_ok = False ,
622
+ deduce_this_ok = False ,
623
+ end = ">" ,
616
624
)
617
625
618
626
params .append (param )
@@ -1761,6 +1769,7 @@ def _parse_parameter(
1761
1769
tok : typing .Optional [LexToken ],
1762
1770
cls : typing .Type [PT ],
1763
1771
concept_ok : bool ,
1772
+ deduce_this_ok : bool ,
1764
1773
end : str = ")" ,
1765
1774
) -> typing .Tuple [PT , typing .Optional [Type ]]:
1766
1775
"""
@@ -1775,6 +1784,10 @@ def _parse_parameter(
1775
1784
param_pack = False
1776
1785
parsed_type : typing .Optional [Type ]
1777
1786
at_type : typing .Optional [Type ] = None
1787
+ extras : typing .Dict [str , typing .Any ] = {}
1788
+
1789
+ if deduce_this_ok and self .lex .token_if ("this" ):
1790
+ extras ["deduces_this" ] = True
1778
1791
1779
1792
if not tok :
1780
1793
tok = self .lex .token ()
@@ -1825,12 +1838,18 @@ def _parse_parameter(
1825
1838
if at_type and self .lex .token_if ("ELLIPSIS" ):
1826
1839
param_pack = True
1827
1840
1828
- param = cls (type = dtype , name = param_name , default = default , param_pack = param_pack )
1841
+ param = cls (
1842
+ type = dtype ,
1843
+ name = param_name ,
1844
+ default = default ,
1845
+ param_pack = param_pack ,
1846
+ ** extras ,
1847
+ )
1829
1848
self .debug_print ("parameter: %s" , param )
1830
1849
return param , at_type
1831
1850
1832
1851
def _parse_parameters (
1833
- self , concept_ok : bool
1852
+ self , concept_ok : bool , deduce_this_ok : bool
1834
1853
) -> typing .Tuple [typing .List [Parameter ], bool , typing .List [TemplateParam ]]:
1835
1854
"""
1836
1855
Consumes function parameters and returns them, and vararg if found, and
@@ -1854,7 +1873,13 @@ def _parse_parameters(
1854
1873
self ._next_token_must_be (")" )
1855
1874
break
1856
1875
1857
- param , at_type = self ._parse_parameter (None , Parameter , concept_ok )
1876
+ # Deduce-this only applicable for first function parameter
1877
+ param , at_type = self ._parse_parameter (
1878
+ None ,
1879
+ Parameter ,
1880
+ concept_ok ,
1881
+ deduce_this_ok = deduce_this_ok and len (params ) == 0 ,
1882
+ )
1858
1883
params .append (param )
1859
1884
if at_type :
1860
1885
at_params .append (
@@ -2047,7 +2072,9 @@ def _parse_function(
2047
2072
state .location = location
2048
2073
is_class_block = isinstance (state , ClassBlockState )
2049
2074
2050
- params , vararg , at_params = self ._parse_parameters (True )
2075
+ params , vararg , at_params = self ._parse_parameters (
2076
+ True , deduce_this_ok = is_class_block
2077
+ )
2051
2078
2052
2079
# Promote abbreviated template parameters
2053
2080
if at_params :
@@ -2243,7 +2270,7 @@ def _parse_cv_ptr_or_fn(
2243
2270
toks = self ._consume_balanced_tokens (gtok )
2244
2271
self .lex .return_tokens (toks [1 :- 1 ])
2245
2272
2246
- fn_params , vararg , _ = self ._parse_parameters (False )
2273
+ fn_params , vararg , _ = self ._parse_parameters (False , False )
2247
2274
2248
2275
assert not isinstance (dtype , FunctionType )
2249
2276
dtype = dtype_fn = FunctionType (dtype , fn_params , vararg )
@@ -2273,7 +2300,7 @@ def _parse_cv_ptr_or_fn(
2273
2300
assert not isinstance (dtype , FunctionType )
2274
2301
dtype = self ._parse_array_type (aptok , dtype )
2275
2302
elif aptok .type == "(" :
2276
- fn_params , vararg , _ = self ._parse_parameters (False )
2303
+ fn_params , vararg , _ = self ._parse_parameters (False , False )
2277
2304
# the type we already have is the return type of the function pointer
2278
2305
2279
2306
assert not isinstance (dtype , FunctionType )
0 commit comments