mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Updated cpplint.py and fixed its regexes for C-style casts (#193)
Additional C-style cast warnings thrown were also fixed.
This commit is contained in:
committed by
Peter Johnson
parent
e8f1fdda44
commit
3819cd0768
25
styleguide/cpplint.py
vendored
25
styleguide/cpplint.py
vendored
@@ -906,7 +906,7 @@ class _CppLintState(object):
|
||||
|
||||
def PrintErrorCounts(self):
|
||||
"""Print a summary of errors by category, and the total."""
|
||||
for category, count in list(self.errors_by_category.items()):
|
||||
for category, count in self.errors_by_category.items():
|
||||
sys.stderr.write('Category \'%s\' errors found: %d\n' %
|
||||
(category, count))
|
||||
sys.stderr.write('Total errors found: %d\n' % self.error_count)
|
||||
@@ -1900,7 +1900,7 @@ def CheckForBadCharacters(filename, lines, error):
|
||||
error: The function to call with any errors found.
|
||||
"""
|
||||
for linenum, line in enumerate(lines):
|
||||
if '\\ufffd' in line:
|
||||
if '\ufffd' in line:
|
||||
error(filename, linenum, 'readability/utf8', 5,
|
||||
'Line contains invalid UTF-8 (or Unicode replacement character).')
|
||||
if '\0' in line:
|
||||
@@ -5108,7 +5108,8 @@ def CheckCasts(filename, clean_lines, linenum, error):
|
||||
|
||||
if not expecting_function:
|
||||
CheckCStyleCast(filename, clean_lines, linenum, 'static_cast',
|
||||
r'\((int|float|double|bool|char|u?int(16|32|64))\)', error)
|
||||
r'\(((unsigned )?(char|(short |long )?int|long)|float|'
|
||||
'double|bool|u?int(8_t|16_t|32_t|64_t))\)', error)
|
||||
|
||||
# This doesn't catch all cases. Consider (const char * const)"hello".
|
||||
#
|
||||
@@ -5120,7 +5121,7 @@ def CheckCasts(filename, clean_lines, linenum, error):
|
||||
else:
|
||||
# Check pointer casts for other than string constants
|
||||
CheckCStyleCast(filename, clean_lines, linenum, 'reinterpret_cast',
|
||||
r'\((\w+\s?\*+\s?)\)', error)
|
||||
r'\(((const )?\w+\s?\*+\s?)\)', error)
|
||||
|
||||
# In addition, we look for people taking the address of a cast. This
|
||||
# is dangerous -- casts can assign to temporaries, so the pointer doesn't
|
||||
@@ -5262,12 +5263,15 @@ _HEADERS_CONTAINING_TEMPLATES = (
|
||||
('<limits>', ('numeric_limits',)),
|
||||
('<list>', ('list',)),
|
||||
('<map>', ('map', 'multimap',)),
|
||||
('<memory>', ('allocator',)),
|
||||
('<memory>', ('allocator', 'make_shared', 'make_unique', 'shared_ptr',
|
||||
'unique_ptr', 'weak_ptr')),
|
||||
('<queue>', ('queue', 'priority_queue',)),
|
||||
('<set>', ('set', 'multiset',)),
|
||||
('<stack>', ('stack',)),
|
||||
('<string>', ('char_traits', 'basic_string',)),
|
||||
('<tuple>', ('tuple',)),
|
||||
('<unordered_map>', ('unordered_map', 'unordered_multimap')),
|
||||
('<unordered_set>', ('unordered_set', 'unordered_multiset')),
|
||||
('<utility>', ('pair',)),
|
||||
('<vector>', ('vector',)),
|
||||
|
||||
@@ -5282,7 +5286,7 @@ _HEADERS_MAYBE_TEMPLATES = (
|
||||
('<algorithm>', ('copy', 'max', 'min', 'min_element', 'sort',
|
||||
'transform',
|
||||
)),
|
||||
('<utility>', ('swap',)),
|
||||
('<utility>', ('forward', 'make_pair', 'move', 'swap')),
|
||||
)
|
||||
|
||||
_RE_PATTERN_STRING = re.compile(r'\bstring\b')
|
||||
@@ -5433,8 +5437,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.
|
||||
|
||||
Reference in New Issue
Block a user