Skip to content

Commit 8d8e5fc

Browse files
authored
Remove IWYU False Positives From Other Namespaces (#273)
This PR removes the false positives from `_HEADERS_CONTAINING_TEMPLATES` that come from non `std` namespaces. Users of boost or other namespaces will no longer get false positives. ```c++ // Warn set<int> blah1; std::set<int> blah2; ::std::set<int> blah2; set<int> blah1; std::set<int> blah2; ::std::set<int> blah2; // NO WARN foo.set<int>(); foo->set<int>(); boost::container::set<int> blah3; blah::std::set<int> blah3; my_std::set<int> blah3; my_set<int> blah4; coolset<int> blah5; std::blah<int> blah6; ::set<int> blah7; ```
1 parent 22c0fe2 commit 8d8e5fc

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

cpplint.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6019,7 +6019,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
60196019
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
60206020
'unique_ptr', 'weak_ptr')),
60216021
('<queue>', ('queue', 'priority_queue',)),
6022-
('<set>', ('multiset',)),
6022+
('<set>', ('set', 'multiset',)),
60236023
('<stack>', ('stack',)),
60246024
('<string>', ('char_traits', 'basic_string',)),
60256025
('<tuple>', ('tuple',)),
@@ -6072,12 +6072,9 @@ def ExpectingFunctionArgs(clean_lines, linenum):
60726072
(re.compile(r'((\bstd::)|[^>.:])\b' + _template + r'(<.*?>)?\([^\)]'),
60736073
_template,
60746074
_header))
6075-
# Match set<type>, but not foo->set<type>, foo.set<type>
6076-
_re_pattern_headers_maybe_templates.append(
6077-
(re.compile(r'[^>.]\bset\s*\<'),
6078-
'set<>',
6079-
'<set>'))
6080-
# Match 'map<type> var' and 'std::map<type>(...)', but not 'map<type>(...)''
6075+
6076+
# Map is often overloaded. Only check, if it is fully qualified.
6077+
# Match 'std::map<type>(...)', but not 'map<type>(...)''
60816078
_re_pattern_headers_maybe_templates.append(
60826079
(re.compile(r'(std\b::\bmap\s*\<)|(^(std\b::\b)map\b\(\s*\<)'),
60836080
'map<>',
@@ -6088,7 +6085,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
60886085
for _header, _templates in _HEADERS_CONTAINING_TEMPLATES:
60896086
for _template in _templates:
60906087
_re_pattern_templates.append(
6091-
(re.compile(r'(\<|\b)' + _template + r'\s*\<'),
6088+
(re.compile(r'((^|(^|\s|((^|\W)::))std::)|[^>.:]\b)' + _template + r'\s*\<'),
60926089
_template + '<>',
60936090
_header))
60946091

cpplint_unittest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,12 @@ def testIncludeWhatYouUse(self):
12491249
auto res = map<Bar>();
12501250
""",
12511251
'')
1252+
# False positive for boost::container::set
1253+
self.TestIncludeWhatYouUse(
1254+
"""
1255+
boost::container::set<int> foo;
1256+
""",
1257+
'')
12521258

12531259
def testFilesBelongToSameModule(self):
12541260
f = cpplint.FilesBelongToSameModule

0 commit comments

Comments
 (0)