Skip to content

Commit 81476f2

Browse files
lhchaveztheandrewdavis
authored andcommitted
Support C++11 types in build/include_what_you_use
This change adds support for forward, make_pair, make_shared,, make_unique, move, shared_ptr, unique_ptr, unordered_map, unordered_multimap, unordered_multiset, unordered_set, weak_ptr. Closes cpplint#133.
1 parent b11cdb0 commit 81476f2

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

cpplint.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -5520,12 +5520,15 @@ def ExpectingFunctionArgs(clean_lines, linenum):
55205520
('<limits>', ('numeric_limits',)),
55215521
('<list>', ('list',)),
55225522
('<map>', ('map', 'multimap',)),
5523-
('<memory>', ('allocator',)),
5523+
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
5524+
'unique_ptr', 'weak_ptr')),
55245525
('<queue>', ('queue', 'priority_queue',)),
55255526
('<set>', ('set', 'multiset',)),
55265527
('<stack>', ('stack',)),
55275528
('<string>', ('char_traits', 'basic_string',)),
55285529
('<tuple>', ('tuple',)),
5530+
('<unordered_map>', ('unordered_map', 'unordered_multimap')),
5531+
('<unordered_set>', ('unordered_set', 'unordered_multiset')),
55295532
('<utility>', ('pair',)),
55305533
('<vector>', ('vector',)),
55315534

@@ -5540,7 +5543,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
55405543
('<algorithm>', ('copy', 'max', 'min', 'min_element', 'sort',
55415544
'transform',
55425545
)),
5543-
('<utility>', ('swap',)),
5546+
('<utility>', ('forward', 'make_pair', 'move', 'swap')),
55445547
)
55455548

55465549
_RE_PATTERN_STRING = re.compile(r'\bstring\b')

cpplint_unittest.py

+43
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,12 @@ def testIncludeWhatYouUse(self):
954954
""",
955955
'Add #include <utility> for pair<>'
956956
' [build/include_what_you_use] [4]')
957+
self.TestIncludeWhatYouUse(
958+
"""#include <hash_map>
959+
auto foo = std::make_pair(1, 2);
960+
""",
961+
'Add #include <utility> for make_pair'
962+
' [build/include_what_you_use] [4]')
957963
self.TestIncludeWhatYouUse(
958964
"""#include <utility>
959965
std::pair<int,int> foo;
@@ -1046,6 +1052,18 @@ def testIncludeWhatYouUse(self):
10461052
""",
10471053
'Add #include <map> for multimap<>'
10481054
' [build/include_what_you_use] [4]')
1055+
self.TestIncludeWhatYouUse(
1056+
"""#include <string>
1057+
void a(const std::unordered_map<int,string> &foobar);
1058+
""",
1059+
'Add #include <unordered_map> for unordered_map<>'
1060+
' [build/include_what_you_use] [4]')
1061+
self.TestIncludeWhatYouUse(
1062+
"""#include <string>
1063+
void a(const std::unordered_set<int> &foobar);
1064+
""",
1065+
'Add #include <unordered_set> for unordered_set<>'
1066+
' [build/include_what_you_use] [4]')
10491067
self.TestIncludeWhatYouUse(
10501068
"""#include <queue>
10511069
void a(const std::priority_queue<int> &foobar);
@@ -1069,6 +1087,31 @@ def testIncludeWhatYouUse(self):
10691087
int i = numeric_limits<int>::max()
10701088
""",
10711089
'')
1090+
self.TestIncludeWhatYouUse(
1091+
"""#include <string>
1092+
std::unique_ptr<int> x;
1093+
""",
1094+
'Add #include <memory> for unique_ptr<>'
1095+
' [build/include_what_you_use] [4]')
1096+
self.TestIncludeWhatYouUse(
1097+
"""#include <string>
1098+
auto x = std::make_unique<int>(0);
1099+
""",
1100+
'Add #include <memory> for make_unique<>'
1101+
' [build/include_what_you_use] [4]')
1102+
self.TestIncludeWhatYouUse(
1103+
"""#include <vector>
1104+
vector<int> foo(vector<int> x) { return std::move(x); }
1105+
""",
1106+
'Add #include <utility> for move'
1107+
' [build/include_what_you_use] [4]')
1108+
self.TestIncludeWhatYouUse(
1109+
"""#include <string>
1110+
int a, b;
1111+
std::swap(a, b);
1112+
""",
1113+
'Add #include <utility> for swap'
1114+
' [build/include_what_you_use] [4]')
10721115

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

0 commit comments

Comments
 (0)