mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Merge f947b7ee504eda7157883bc96d979c7601d0a49f into 8487c083e1faecb1259be8a8873618cfdb69d33d
This commit is contained in:
commit
78824872af
35
cpplint/cpplint.py
vendored
35
cpplint/cpplint.py
vendored
@ -5396,12 +5396,10 @@ _RE_PATTERN_STRING = re.compile(r'\bstring\b')
|
|||||||
_re_pattern_headers_maybe_templates = []
|
_re_pattern_headers_maybe_templates = []
|
||||||
for _header, _templates in _HEADERS_MAYBE_TEMPLATES:
|
for _header, _templates in _HEADERS_MAYBE_TEMPLATES:
|
||||||
for _template in _templates:
|
for _template in _templates:
|
||||||
# Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max or
|
# Match max<type>(..., ...), max(..., ...), but not foo->max or foo.max.
|
||||||
# type::max().
|
|
||||||
_re_pattern_headers_maybe_templates.append(
|
_re_pattern_headers_maybe_templates.append(
|
||||||
(re.compile(r'[^>.]\b' + _template + r'(<.*?>)?\([^\)]'),
|
(re.compile(r'(?<![>.])\b' + _template + r'(<.*?>)?\([^\)]'), _template,
|
||||||
_template,
|
_header))
|
||||||
_header))
|
|
||||||
|
|
||||||
# Other scripts may reach in and modify this pattern.
|
# Other scripts may reach in and modify this pattern.
|
||||||
_re_pattern_templates = []
|
_re_pattern_templates = []
|
||||||
@ -5495,6 +5493,18 @@ def UpdateIncludeState(filename, include_dict, io=codecs):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def UpdateRequiredHeadersForLine(patterns, line, linenum, required):
|
||||||
|
for pattern, template, header in patterns:
|
||||||
|
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)
|
||||||
|
return required
|
||||||
|
|
||||||
|
|
||||||
def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
|
def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
|
||||||
io=codecs):
|
io=codecs):
|
||||||
"""Reports for missing stl includes.
|
"""Reports for missing stl includes.
|
||||||
@ -5530,22 +5540,15 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
|
|||||||
if prefix.endswith('std::') or not prefix.endswith('::'):
|
if prefix.endswith('std::') or not prefix.endswith('::'):
|
||||||
required['<string>'] = (linenum, 'string')
|
required['<string>'] = (linenum, 'string')
|
||||||
|
|
||||||
for pattern, template, header in _re_pattern_headers_maybe_templates:
|
required = UpdateRequiredHeadersForLine(_re_pattern_headers_maybe_templates,
|
||||||
if pattern.search(line):
|
line, linenum, required)
|
||||||
required[header] = (linenum, template)
|
|
||||||
|
|
||||||
# The following function is just a speed up, no semantics are changed.
|
# The following function is just a speed up, no semantics are changed.
|
||||||
if not '<' in line: # Reduces the cpu time usage by skipping lines.
|
if not '<' in line: # Reduces the cpu time usage by skipping lines.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for pattern, template, header in _re_pattern_templates:
|
required = UpdateRequiredHeadersForLine(_re_pattern_templates, line,
|
||||||
matched = pattern.search(line)
|
linenum, required)
|
||||||
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
|
# 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.
|
# include it again in foo.cc. Here, we will look at possible includes.
|
||||||
|
@ -968,6 +968,16 @@ class CpplintTest(CpplintTestBase):
|
|||||||
base::hash_map<int, int> foobar;
|
base::hash_map<int, int> foobar;
|
||||||
""",
|
""",
|
||||||
'')
|
'')
|
||||||
|
self.TestIncludeWhatYouUse(
|
||||||
|
"""#include "base/ranges/algorithm.h"
|
||||||
|
base::ranges::copy(foo, bar.begin());
|
||||||
|
""",
|
||||||
|
'')
|
||||||
|
self.TestIncludeWhatYouUse(
|
||||||
|
"""#include "base/foobar.h"
|
||||||
|
void FooBar::Remove(size_t index);
|
||||||
|
""",
|
||||||
|
'')
|
||||||
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…
x
Reference in New Issue
Block a user