diff --git a/cpplint.py b/cpplint.py index 8ca6471..3344a29 100755 --- a/cpplint.py +++ b/cpplint.py @@ -5529,11 +5529,11 @@ def ExpectingFunctionArgs(clean_lines, linenum): )), ('', ('numeric_limits',)), ('', ('list',)), - ('', ('map', 'multimap',)), + ('', ('multimap',)), ('', ('allocator', 'make_shared', 'make_unique', 'shared_ptr', 'unique_ptr', 'weak_ptr')), ('', ('queue', 'priority_queue',)), - ('', ('set', 'multiset',)), + ('', ('multiset',)), ('', ('stack',)), ('', ('char_traits', 'basic_string',)), ('', ('tuple',)), @@ -5567,6 +5567,16 @@ def ExpectingFunctionArgs(clean_lines, linenum): (re.compile(r'[^>.]\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(...)'' +_re_pattern_headers_maybe_templates.append( + (re.compile(r'(std\b::\bmap\s*\<)|(^(std\b::\b)map\b\(\s*\<)'), + 'map<>', + '')) # Other scripts may reach in and modify this pattern. _re_pattern_templates = [] diff --git a/cpplint_unittest.py b/cpplint_unittest.py index 30cc660..0acedee 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -1112,6 +1112,35 @@ def testIncludeWhatYouUse(self): """, 'Add #include for swap' ' [build/include_what_you_use] [4]') + # False positive for std::set + self.TestIncludeWhatYouUse( + """ + #include + struct Foo { + template + void set(const std::string& name, const T& value); + }; + Foo bar; + Foo* pbar = &bar; + bar.set("int", 5); + pbar->set("bool", false);""", + '') + # False positive for std::map + self.TestIncludeWhatYouUse( + """ + template + struct Foo { + T t; + }; + template + Foo map(T t) { + return Foo{ t }; + } + struct Bar { + }; + auto res = map(); + """, + '') # Test the UpdateIncludeState code path. mock_header_contents = ['#include "blah/foo.h"', '#include "blah/bar.h"']