Skip to content

Commit 8b26317

Browse files
authored
Merge pull request google#158 from lhchavez/iwyu
Make build/include_what_you_use more consistent
2 parents f15e633 + 3ae81f1 commit 8b26317

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cpplint/cpplint.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5433,8 +5433,13 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
54335433
continue
54345434

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

54395444
# The policy is that if you #include something in foo.h you don't need to
54405445
# include it again in foo.cc. Here, we will look at possible includes.

cpplint/cpplint_unittest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,11 @@ def testIncludeWhatYouUse(self):
949949
""",
950950
'Add #include <hash_map> for hash_map<>'
951951
' [build/include_what_you_use] [4]')
952+
self.TestIncludeWhatYouUse(
953+
"""#include "base/containers/hash_tables.h"
954+
base::hash_map<int, int> foobar;
955+
""",
956+
'')
952957
self.TestIncludeWhatYouUse(
953958
"""#include "base/foobar.h"
954959
bool foobar = std::less<int>(0,1);

0 commit comments

Comments
 (0)