Skip to content

Commit 6d3a7d8

Browse files
authored
Merge pull request google#159 from lhchavez/cpp11
Support C++11 types in build/include_what_you_use
2 parents c628808 + 2890dff commit 6d3a7d8

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

cpplint/cpplint.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,12 +5262,15 @@ def ExpectingFunctionArgs(clean_lines, linenum):
52625262
('<limits>', ('numeric_limits',)),
52635263
('<list>', ('list',)),
52645264
('<map>', ('map', 'multimap',)),
5265-
('<memory>', ('allocator',)),
5265+
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
5266+
'unique_ptr', 'weak_ptr')),
52665267
('<queue>', ('queue', 'priority_queue',)),
52675268
('<set>', ('set', 'multiset',)),
52685269
('<stack>', ('stack',)),
52695270
('<string>', ('char_traits', 'basic_string',)),
52705271
('<tuple>', ('tuple',)),
5272+
('<unordered_map>', ('unordered_map', 'unordered_multimap')),
5273+
('<unordered_set>', ('unordered_set', 'unordered_multiset')),
52715274
('<utility>', ('pair',)),
52725275
('<vector>', ('vector',)),
52735276

@@ -5282,7 +5285,7 @@ def ExpectingFunctionArgs(clean_lines, linenum):
52825285
('<algorithm>', ('copy', 'max', 'min', 'min_element', 'sort',
52835286
'transform',
52845287
)),
5285-
('<utility>', ('swap',)),
5288+
('<utility>', ('forward', 'make_pair', 'move', 'swap')),
52865289
)
52875290

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

cpplint/cpplint_unittest.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,12 @@ def testIncludeWhatYouUse(self):
910910
""",
911911
'Add #include <utility> for pair<>'
912912
' [build/include_what_you_use] [4]')
913+
self.TestIncludeWhatYouUse(
914+
"""#include <hash_map>
915+
auto foo = std::make_pair(1, 2);
916+
""",
917+
'Add #include <utility> for make_pair'
918+
' [build/include_what_you_use] [4]')
913919
self.TestIncludeWhatYouUse(
914920
"""#include <utility>
915921
std::pair<int,int> foo;
@@ -1002,6 +1008,18 @@ def testIncludeWhatYouUse(self):
10021008
""",
10031009
'Add #include <map> for multimap<>'
10041010
' [build/include_what_you_use] [4]')
1011+
self.TestIncludeWhatYouUse(
1012+
"""#include <string>
1013+
void a(const std::unordered_map<int,string> &foobar);
1014+
""",
1015+
'Add #include <unordered_map> for unordered_map<>'
1016+
' [build/include_what_you_use] [4]')
1017+
self.TestIncludeWhatYouUse(
1018+
"""#include <string>
1019+
void a(const std::unordered_set<int> &foobar);
1020+
""",
1021+
'Add #include <unordered_set> for unordered_set<>'
1022+
' [build/include_what_you_use] [4]')
10051023
self.TestIncludeWhatYouUse(
10061024
"""#include <queue>
10071025
void a(const std::priority_queue<int> &foobar);
@@ -1025,6 +1043,31 @@ def testIncludeWhatYouUse(self):
10251043
int i = numeric_limits<int>::max()
10261044
""",
10271045
'')
1046+
self.TestIncludeWhatYouUse(
1047+
"""#include <string>
1048+
std::unique_ptr<int> x;
1049+
""",
1050+
'Add #include <memory> for unique_ptr<>'
1051+
' [build/include_what_you_use] [4]')
1052+
self.TestIncludeWhatYouUse(
1053+
"""#include <string>
1054+
auto x = std::make_unique<int>(0);
1055+
""",
1056+
'Add #include <memory> for make_unique<>'
1057+
' [build/include_what_you_use] [4]')
1058+
self.TestIncludeWhatYouUse(
1059+
"""#include <vector>
1060+
vector<int> foo(vector<int> x) { return std::move(x); }
1061+
""",
1062+
'Add #include <utility> for move'
1063+
' [build/include_what_you_use] [4]')
1064+
self.TestIncludeWhatYouUse(
1065+
"""#include <string>
1066+
int a, b;
1067+
std::swap(a, b);
1068+
""",
1069+
'Add #include <utility> for swap'
1070+
' [build/include_what_you_use] [4]')
10281071

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

0 commit comments

Comments
 (0)