From 6440ff34938e9f1765019c1c4d52cac0c9c62e1c Mon Sep 17 00:00:00 2001 From: Geoffrey Viola Date: Mon, 20 May 2024 17:26:53 +0000 Subject: [PATCH] Remove IWYU False Positives From Other Namespaces --- cpplint.py | 13 +++++-------- cpplint_unittest.py | 6 ++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cpplint.py b/cpplint.py index 9d4ff5a..d98c659 100755 --- a/cpplint.py +++ b/cpplint.py @@ -6019,7 +6019,7 @@ def ExpectingFunctionArgs(clean_lines, linenum): ('', ('allocator', 'make_shared', 'make_unique', 'shared_ptr', 'unique_ptr', 'weak_ptr')), ('', ('queue', 'priority_queue',)), - ('', ('multiset',)), + ('', ('set', 'multiset',)), ('', ('stack',)), ('', ('char_traits', 'basic_string',)), ('', ('tuple',)), @@ -6072,12 +6072,9 @@ def ExpectingFunctionArgs(clean_lines, linenum): (re.compile(r'((\bstd::)|[^>.:])\b' + _template + r'(<.*?>)?\([^\)]'), _template, _header)) -# Match set, but not foo->set, foo.set -_re_pattern_headers_maybe_templates.append( - (re.compile(r'[^>.]\bset\s*\<'), - 'set<>', - '')) -# Match 'map var' and 'std::map(...)', but not 'map(...)'' + +# Map is often overloaded. Only check, if it is fully qualified. +# Match 'std::map(...)', but not 'map(...)'' _re_pattern_headers_maybe_templates.append( (re.compile(r'(std\b::\bmap\s*\<)|(^(std\b::\b)map\b\(\s*\<)'), 'map<>', @@ -6088,7 +6085,7 @@ def ExpectingFunctionArgs(clean_lines, linenum): for _header, _templates in _HEADERS_CONTAINING_TEMPLATES: for _template in _templates: _re_pattern_templates.append( - (re.compile(r'(\<|\b)' + _template + r'\s*\<'), + (re.compile(r'((^|(^|\s|((^|\W)::))std::)|[^>.:]\b)' + _template + r'\s*\<'), _template + '<>', _header)) diff --git a/cpplint_unittest.py b/cpplint_unittest.py index fb63c9d..142a495 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -1249,6 +1249,12 @@ def testIncludeWhatYouUse(self): auto res = map(); """, '') + # False positive for boost::container::set + self.TestIncludeWhatYouUse( + """ + boost::container::set foo; + """, + '') def testFilesBelongToSameModule(self): f = cpplint.FilesBelongToSameModule