Skip to content

Commit adb3500

Browse files
Vladislav Vinogradovtkruse
authored andcommitted
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
1 parent 5f69834 commit adb3500

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cpplint.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5614,7 +5614,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
56145614
)),
56155615
('<limits>', ('numeric_limits',)),
56165616
('<list>', ('list',)),
5617-
('<map>', ('map', 'multimap',)),
5617+
('<map>', ('multimap',)),
56185618
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
56195619
'unique_ptr', 'weak_ptr')),
56205620
('<queue>', ('queue', 'priority_queue',)),
@@ -5657,6 +5657,11 @@ def ExpectingFunctionArgs(clean_lines, linenum):
56575657
(re.compile(r'[^>.]\bset\s*\<'),
56585658
'set<>',
56595659
'<set>'))
5660+
# Match 'map<type> var' and 'std::map<type>(...)', but not 'map<type>(...)''
5661+
_re_pattern_headers_maybe_templates.append(
5662+
(re.compile(r'(std\b::\bmap\s*\<)|(^(std\b::\b)map\b\(\s*\<)'),
5663+
'map<>',
5664+
'<map>'))
56605665

56615666
# Other scripts may reach in and modify this pattern.
56625667
_re_pattern_templates = []

cpplint_unittest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,22 @@ def testIncludeWhatYouUse(self):
11321132
bar.set<int>("int", 5);
11331133
pbar->set<bool>("bool", false);""",
11341134
'')
1135+
# False positive for std::map
1136+
self.TestIncludeWhatYouUse(
1137+
"""
1138+
template <typename T>
1139+
struct Foo {
1140+
T t;
1141+
};
1142+
template <typename T>
1143+
Foo<T> map(T t) {
1144+
return Foo<T>{ t };
1145+
}
1146+
struct Bar {
1147+
};
1148+
auto res = map<Bar>();
1149+
""",
1150+
'')
11351151

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy