Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5529,11 +5529,11 @@ def ExpectingFunctionArgs(clean_lines, linenum):
)),
('<limits>', ('numeric_limits',)),
('<list>', ('list',)),
('<map>', ('map', 'multimap',)),
('<map>', ('multimap',)),
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
'unique_ptr', 'weak_ptr')),
('<queue>', ('queue', 'priority_queue',)),
('<set>', ('set', 'multiset',)),
('<set>', ('multiset',)),
('<stack>', ('stack',)),
('<string>', ('char_traits', 'basic_string',)),
('<tuple>', ('tuple',)),
Expand Down Expand Up @@ -5567,6 +5567,16 @@ def ExpectingFunctionArgs(clean_lines, linenum):
(re.compile(r'[^>.]\b' + _template + r'(<.*?>)?\([^\)]'),
_template,
_header))
# Match set<type>, but not foo->set<type>, foo.set<type>
_re_pattern_headers_maybe_templates.append(
(re.compile(r'[^>.]\bset\s*\<'),
'set<>',
'<set>'))
# Match 'map<type> var' and 'std::map<type>(...)', but not 'map<type>(...)''
_re_pattern_headers_maybe_templates.append(
(re.compile(r'(std\b::\bmap\s*\<)|(^(std\b::\b)map\b\(\s*\<)'),
'map<>',
'<map>'))

# Other scripts may reach in and modify this pattern.
_re_pattern_templates = []
Expand Down
29 changes: 29 additions & 0 deletions cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,35 @@ def testIncludeWhatYouUse(self):
""",
'Add #include <utility> for swap'
' [build/include_what_you_use] [4]')
# False positive for std::set
self.TestIncludeWhatYouUse(
"""
#include <string>
struct Foo {
template <typename T>
void set(const std::string& name, const T& value);
};
Foo bar;
Foo* pbar = &bar;
bar.set<int>("int", 5);
pbar->set<bool>("bool", false);""",
'')
# False positive for std::map
self.TestIncludeWhatYouUse(
"""
template <typename T>
struct Foo {
T t;
};
template <typename T>
Foo<T> map(T t) {
return Foo<T>{ t };
}
struct Bar {
};
auto res = map<Bar>();
""",
'')

# Test the UpdateIncludeState code path.
mock_header_contents = ['#include "blah/foo.h"', '#include "blah/bar.h"']
Expand Down