Skip to content
Permalink
Browse files

Add special case for std::map template usage

Avoid false positive for [build/include_what_you_use]
in case of `map` is user defined function
  • Loading branch information...
vinograd47 authored and tkruse committed Jul 25, 2019
1 parent 5f69834 commit adb3500107f409ac5491188ae652ac3f4d03d9d3
Showing with 22 additions and 1 deletion.
  1. +6 −1 cpplint.py
  2. +16 −0 cpplint_unittest.py
@@ -5614,7 +5614,7 @@ 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',)),
@@ -5657,6 +5657,11 @@ def ExpectingFunctionArgs(clean_lines, linenum):
(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 = []
@@ -1132,6 +1132,22 @@ def testIncludeWhatYouUse(self):
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"']

0 comments on commit adb3500

Please sign in to comment.
You can’t perform that action at this time.