@@ -5348,12 +5348,10 @@ def ExpectingFunctionArgs(clean_lines, linenum):
5348
5348
_re_pattern_headers_maybe_templates = []
5349
5349
for _header , _templates in _HEADERS_MAYBE_TEMPLATES :
5350
5350
for _template in _templates :
5351
- # Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max
5352
- # or type::max().
5351
+ # Match max<type>(..., ...), max(..., ...), but not foo->max or foo.max.
5353
5352
_re_pattern_headers_maybe_templates .append (
5354
- (re .compile (r'[^>.]\b' + _template + r'(<.*?>)?\([^\)]' ),
5355
- _template ,
5356
- _header ))
5353
+ (re .compile (r'(?<![>.]\b)' + _template + r'(<.*?>)?\([^\)]' ), _template ,
5354
+ _header ))
5357
5355
5358
5356
# Other scripts may reach in and modify this pattern.
5359
5357
_re_pattern_templates = []
@@ -5447,6 +5445,18 @@ def UpdateIncludeState(filename, include_dict, io=codecs):
5447
5445
return True
5448
5446
5449
5447
5448
+ def UpdateRequiredHeadersForLine (patterns , line , linenum , required ):
5449
+ for pattern , template , header in patterns :
5450
+ matched = pattern .search (line )
5451
+ if matched :
5452
+ # Don't warn about IWYU in non-STL namespaces:
5453
+ # (We check only the first match per line; good enough.)
5454
+ prefix = line [:matched .start ()]
5455
+ if prefix .endswith ('std::' ) or not prefix .endswith ('::' ):
5456
+ required [header ] = (linenum , template )
5457
+ return required
5458
+
5459
+
5450
5460
def CheckForIncludeWhatYouUse (filename , clean_lines , include_state , error ,
5451
5461
io = codecs ):
5452
5462
"""Reports for missing stl includes.
@@ -5482,22 +5492,15 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
5482
5492
if prefix .endswith ('std::' ) or not prefix .endswith ('::' ):
5483
5493
required ['<string>' ] = (linenum , 'string' )
5484
5494
5485
- for pattern , template , header in _re_pattern_headers_maybe_templates :
5486
- if pattern .search (line ):
5487
- required [header ] = (linenum , template )
5495
+ required = UpdateRequiredHeadersForLine (_re_pattern_headers_maybe_templates ,
5496
+ line , linenum , required )
5488
5497
5489
5498
# The following function is just a speed up, no semantics are changed.
5490
5499
if not '<' in line : # Reduces the cpu time usage by skipping lines.
5491
5500
continue
5492
5501
5493
- for pattern , template , header in _re_pattern_templates :
5494
- matched = pattern .search (line )
5495
- if matched :
5496
- # Don't warn about IWYU in non-STL namespaces:
5497
- # (We check only the first match per line; good enough.)
5498
- prefix = line [:matched .start ()]
5499
- if prefix .endswith ('std::' ) or not prefix .endswith ('::' ):
5500
- required [header ] = (linenum , template )
5502
+ required = UpdateRequiredHeadersForLine (_re_pattern_templates , line ,
5503
+ linenum , required )
5501
5504
5502
5505
# The policy is that if you #include something in foo.h you don't need to
5503
5506
# include it again in foo.cc. Here, we will look at possible includes.
0 commit comments