From 2890dffc1fcf561edea7d6c9447e205c268d9433 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Mon, 11 Jul 2016 19:37:29 -0700 Subject: [PATCH] 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 #133. --- cpplint/cpplint.py | 7 ++++-- cpplint/cpplint_unittest.py | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index f4b1113..d860e3c 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -5262,12 +5262,15 @@ _HEADERS_CONTAINING_TEMPLATES = ( ('', ('numeric_limits',)), ('', ('list',)), ('', ('map', 'multimap',)), - ('', ('allocator',)), + ('', ('allocator', 'make_shared', 'make_unique', 'shared_ptr', + 'unique_ptr', 'weak_ptr')), ('', ('queue', 'priority_queue',)), ('', ('set', 'multiset',)), ('', ('stack',)), ('', ('char_traits', 'basic_string',)), ('', ('tuple',)), + ('', ('unordered_map', 'unordered_multimap')), + ('', ('unordered_set', 'unordered_multiset')), ('', ('pair',)), ('', ('vector',)), @@ -5282,7 +5285,7 @@ _HEADERS_MAYBE_TEMPLATES = ( ('', ('copy', 'max', 'min', 'min_element', 'sort', 'transform', )), - ('', ('swap',)), + ('', ('forward', 'make_pair', 'move', 'swap')), ) _RE_PATTERN_STRING = re.compile(r'\bstring\b') diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index 07a443f..dbd52cb 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -910,6 +910,12 @@ class CpplintTest(CpplintTestBase): """, 'Add #include for pair<>' ' [build/include_what_you_use] [4]') + self.TestIncludeWhatYouUse( + """#include + auto foo = std::make_pair(1, 2); + """, + 'Add #include for make_pair' + ' [build/include_what_you_use] [4]') self.TestIncludeWhatYouUse( """#include std::pair foo; @@ -997,6 +1003,18 @@ class CpplintTest(CpplintTestBase): """, 'Add #include for multimap<>' ' [build/include_what_you_use] [4]') + self.TestIncludeWhatYouUse( + """#include + void a(const std::unordered_map &foobar); + """, + 'Add #include for unordered_map<>' + ' [build/include_what_you_use] [4]') + self.TestIncludeWhatYouUse( + """#include + void a(const std::unordered_set &foobar); + """, + 'Add #include for unordered_set<>' + ' [build/include_what_you_use] [4]') self.TestIncludeWhatYouUse( """#include void a(const std::priority_queue &foobar); @@ -1020,6 +1038,31 @@ class CpplintTest(CpplintTestBase): int i = numeric_limits::max() """, '') + self.TestIncludeWhatYouUse( + """#include + std::unique_ptr x; + """, + 'Add #include for unique_ptr<>' + ' [build/include_what_you_use] [4]') + self.TestIncludeWhatYouUse( + """#include + auto x = std::make_unique(0); + """, + 'Add #include for make_unique<>' + ' [build/include_what_you_use] [4]') + self.TestIncludeWhatYouUse( + """#include + vector foo(vector x) { return std::move(x); } + """, + 'Add #include for move' + ' [build/include_what_you_use] [4]') + self.TestIncludeWhatYouUse( + """#include + int a, b; + std::swap(a, b); + """, + 'Add #include for swap' + ' [build/include_what_you_use] [4]') # Test the UpdateIncludeState code path. mock_header_contents = ['#include "blah/foo.h"', '#include "blah/bar.h"']