Skip to content

Commit

Permalink
Make build/include_what_you_use more consistent
Browse files Browse the repository at this point in the history
`std::string` has some logic to omit the suggestion if it is used in
non-STL namespaces, so the same check should be OK to use for other
types. Closes google#157.
  • Loading branch information
lhchavez committed Jul 12, 2016
1 parent f15e633 commit 3ae81f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cpplint/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5433,8 +5433,13 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
continue

for pattern, template, header in _re_pattern_templates:
if pattern.search(line):
required[header] = (linenum, template)
matched = pattern.search(line)
if matched:
# Don't warn about IWYU in non-STL namespaces:
# (We check only the first match per line; good enough.)
prefix = line[:matched.start()]
if prefix.endswith('std::') or not prefix.endswith('::'):
required[header] = (linenum, template)

# The policy is that if you #include something in foo.h you don't need to
# include it again in foo.cc. Here, we will look at possible includes.
Expand Down
5 changes: 5 additions & 0 deletions cpplint/cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,11 @@ def testIncludeWhatYouUse(self):
""",
'Add #include <hash_map> for hash_map<>'
' [build/include_what_you_use] [4]')
self.TestIncludeWhatYouUse(
"""#include "base/containers/hash_tables.h"
base::hash_map<int, int> foobar;
""",
'')
self.TestIncludeWhatYouUse(
"""#include "base/foobar.h"
bool foobar = std::less<int>(0,1);
Expand Down

0 comments on commit 3ae81f1

Please sign in to comment.