mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Make build/include_what_you_use more consistent
`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 #157.
This commit is contained in:
parent
f15e633de5
commit
3ae81f1911
7
cpplint/cpplint.py
vendored
7
cpplint/cpplint.py
vendored
|
@ -5433,7 +5433,12 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for pattern, template, header in _re_pattern_templates:
|
for pattern, template, header in _re_pattern_templates:
|
||||||
if pattern.search(line):
|
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)
|
required[header] = (linenum, template)
|
||||||
|
|
||||||
# The policy is that if you #include something in foo.h you don't need to
|
# The policy is that if you #include something in foo.h you don't need to
|
||||||
|
|
|
@ -949,6 +949,11 @@ class CpplintTest(CpplintTestBase):
|
||||||
""",
|
""",
|
||||||
'Add #include <hash_map> for hash_map<>'
|
'Add #include <hash_map> for hash_map<>'
|
||||||
' [build/include_what_you_use] [4]')
|
' [build/include_what_you_use] [4]')
|
||||||
|
self.TestIncludeWhatYouUse(
|
||||||
|
"""#include "base/containers/hash_tables.h"
|
||||||
|
base::hash_map<int, int> foobar;
|
||||||
|
""",
|
||||||
|
'')
|
||||||
self.TestIncludeWhatYouUse(
|
self.TestIncludeWhatYouUse(
|
||||||
"""#include "base/foobar.h"
|
"""#include "base/foobar.h"
|
||||||
bool foobar = std::less<int>(0,1);
|
bool foobar = std::less<int>(0,1);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user