Lines Matching +full:close +full:- +full:nonexistent +full:- +full:disable +full:- +full:issues
31 """Does google-lint on c++ files.
34 be in non-compliance with google style. It does not attempt to fix
35 up these problems -- the point is to educate. It does also not
63 Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
64 [--counting=total|toplevel|detailed] [--root=subdir]
65 [--linelength=digits] [--headers=x,y,...]
66 [--quiet]
70 https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
72 Every problem is given a confidence score from 1-5, with 5 meaning we are
76 To suppress false-positive errors of a certain category, add a
82 extensions with the --extensions flag.
91 Specify a number 0-5 to restrict errors to certain verbosity levels.
96 filter=-x,+y,...
97 Specify a comma-separated list of category-filters to apply: only
101 "-FOO" and "FOO" means "do not print categories that start with FOO".
104 Examples: --filter=-whitespace,+whitespace/braces
105 --filter=whitespace,runtime/printf,+runtime/printf_format
106 --filter=-,+build/include_what_you_use
109 --filter=
114 the top-level categories like 'build' and 'whitespace' will
131 --root=chrome => BROWSER_UI_BROWSER_H_
132 --root=chrome/browser => UI_BROWSER_H_
133 --root=.. => SRC_CHROME_BROWSER_UI_BROWSER_H_
140 --linelength=120
146 --extensions=hpp,cpp
150 automatically added to --extensions list.
153 --headers=hpp,hxx
154 --headers=hpp
156 cpplint.py supports per-directory configurations specified in CPPLINT.cfg
161 filter=+filter1,-filter2,...
169 is usually placed in the top-level project directory.
171 The "filter" option is similar in function to --filter flag. It specifies
173 through --filter command-line flag.
181 The "root" option is similar in function to the --root flag (see example
184 The "headers" option is similar in function to the --headers flag
188 sub-directories, unless overridden by a nested configuration file.
191 filter=-build/include_order,+build/include_alpha
197 file is located) and all sub-directories.
201 # We want an explicit list so we can list them all in cpplint --filter=.
273 # These error categories are no longer enforced by cpplint, but for backwards-
280 # The default state of the category filter. This is overridden by the --filter=
282 # off by default (i.e., categories that must be enabled by the --filter= flags).
283 # All entries here should start with a '-' or '+', as in the --filter= flag.
284 _DEFAULT_FILTERS = ['-build/include_alpha']
296 # We used to check for high-bit characters, but after much discussion we
297 # decided those were OK, as long as they were in UTF-8 and didn't represent
298 # hard-coded international strings, which belong in a separate i18n file.
453 # - Anything not following google file name conventions (containing an
455 # - Lua headers.
457 r'^(?:[^/]*[A-Z][^/]*\.h|lua\.h|lauxlib\.h|lualib\.h)$')
512 # False positives include C-style multi-line comments and multi-line strings
551 # This is set by --root flag.
556 # This is set by --linelength flag.
560 # This is set by --extensions flag.
564 # This is set by --headers flag.
584 """Updates the global list of line error-suppressions.
607 category = category[1:-1]
742 Line number of previous occurrence, or -1 if the header has not
749 return -1
767 self.include_list[-1] = []
775 - replaces "-" with "_" so they both cmp the same.
776 - removes '-inl' since we don't require them to be after the main header.
777 - lowercase everything, just in case.
785 return header_path.replace('-inl.h', '.h').replace('-', '_').lower()
804 Match(r'^\s*#\s*include\b', clean_lines.elided[linenum - 1])):
809 """Returns a non-empty error message if the next header is out of order.
863 """Maintains module-wide state.."""
874 self.quiet = False # Suppress non-error messagess?
877 # "emacs" - format that emacs can parse (default)
878 # "vs7" - format that Microsoft Visual Studio 7 can parse
902 """Sets the error-message filters.
908 filters: A string of comma-separated filters (eg "+whitespace/indent").
909 Each filter should start with + or -; else we die.
912 ValueError: The comma-separated filters did not all start with '+' or '-'.
913 E.g. "-,+whitespace,-whitespace/indent,whitespace/badfilter"
920 """ Adds more filters to the existing list of error-message filters. """
926 if not (filt.startswith('+') or filt.startswith('-')):
927 raise ValueError('Every filter in --filters must start with + or -'
1002 """Sets the module's error-message filters.
1008 filters: A string of comma-separated filters (eg "whitespace/indent").
1009 Each filter should start with + or -; else we die.
1020 filters: A string of comma-separated filters (eg "whitespace/indent").
1021 Each filter should start with + or -; else we die.
1036 _NORMAL_TRIGGER = 250 # for --v=0, 500 for --v=1, etc.
1083 ' %s has %d non-comment lines'
1172 """File base name - text after the final slash, before the final period."""
1176 """File extension - text following the final period."""
1202 if one_filter.startswith('-'):
1233 confidence: A number from 1-5 representing a confidence score for
1253 r'\\([abfnrtv?"\\\']|\d+|x[0-9a-fA-F]+)')
1256 # Matches multi-line C style comments.
1262 # if this doesn't work we try on left side but only if there's a non-character
1274 This function does not consider single-line nor multi-line comments.
1285 return ((line.count('"') - line.count(r'\"') - line.count("'\"'")) & 1) == 1
1293 multi-line string
1352 # Start of a multi-line raw string
1385 """Clears a range of lines for multi-line comments."""
1386 # Having // dummy comments makes the lines non-empty, so we will not get
1393 """Removes multiline (c-style) comments from lines."""
1402 'Could not find end of multi-line comment')
1409 """Removes //-comments and single-line C-style /* */ comments.
1415 The line with single-line comments removed.
1418 if commentpos != -1 and not IsCppString(line[:commentpos]):
1502 if Search(r'\b(?:0[bBxX]?|[1-9])[0-9a-fA-F]*$', head):
1503 match_literal = Match(r'^((?:\'?[0-9a-zA-Z_])*)(.*)$', "'" + tail)
1529 On finding an unclosed expression: (-1, None)
1530 Otherwise: (-1, new stack at end of this line)
1539 if i > 0 and line[i - 1] == '<':
1541 if stack and stack[-1] == '<':
1544 return (-1, None)
1556 while stack and stack[-1] == '<':
1559 return (-1, None)
1560 if ((stack[-1] == '(' and char == ')') or
1561 (stack[-1] == '[' and char == ']') or
1562 (stack[-1] == '{' and char == '}')):
1568 return (-1, None)
1572 # Ignore "->" and operator functions
1574 (line[i - 1] == '-' or Search(r'\boperator\s*$', line[0:i - 1]))):
1580 if stack[-1] == '<':
1588 while stack and stack[-1] == '<':
1591 return (-1, None)
1594 return (-1, stack)
1615 (line, len(lines), -1) if we never find a close. Note we ignore
1622 return (line, clean_lines.NumLines(), -1)
1626 if end_pos > -1:
1630 while stack and linenum < clean_lines.NumLines() - 1:
1634 if end_pos > -1:
1638 return (line, clean_lines.NumLines(), -1)
1654 On finding an unclosed expression: (-1, None)
1655 Otherwise: (-1, new stack at beginning of this line)
1666 # Ignore it if it's a "->" or ">=" or "operator>"
1668 (line[i - 1] == '-' or
1669 Match(r'\s>=\s', line[i - 1:]) or
1671 i -= 1
1676 if i > 0 and line[i - 1] == '<':
1678 i -= 1
1682 if stack and stack[-1] == '>':
1691 while stack and stack[-1] == '>':
1694 return (-1, None)
1695 if ((char == '(' and stack[-1] == ')') or
1696 (char == '[' and stack[-1] == ']') or
1697 (char == '{' and stack[-1] == '}')):
1703 return (-1, None)
1708 while stack and stack[-1] == '>':
1711 return (-1, None)
1713 i -= 1
1715 return (-1, stack)
1731 (line, 0, -1) if we never find the matching opening brace. Note
1737 return (line, 0, -1)
1741 if start_pos > -1:
1746 linenum -= 1
1748 (start_pos, stack) = FindStartOfExpressionInLine(line, len(line) - 1, stack)
1749 if start_pos > -1:
1753 return (line, 0, -1)
1836 # Process the file path with the --root flag if it was set.
1843 # f(['x', 'y'], ['w, z']) -> None (not a valid prefix)
1846 # f(['a, 'b', 'c', 'd'], ['a', 'b']) -> ['c', 'd']
1850 # --root=subdir , lstrips subdir from the header guard
1861 # --root=.. , will prepend the outer directory to the header guard
1878 # --root=FAKE_DIR is ignored
1882 return re.sub(r'[^a-zA-Z0-9]', '_', file_path_from_root).upper() + '_'
1900 # Because this is silencing a warning for a nonexistent line, we
1963 for i in xrange(1, len(raw_lines) - 1):
1991 headerfile = filename[0:len(filename) - len(fileinfo.Extension())] + '.h'
2014 contained invalid UTF-8 (likely) or Unicode replacement characters (which
2016 numbering if the invalid UTF-8 occurred adjacent to a newline.
2028 'Line contains invalid UTF-8 (or Unicode replacement character).')
2045 # last-but-two element of lines() exists and is empty.
2046 if len(lines) < 3 or lines[-2]:
2047 error(filename, len(lines) - 2, 'whitespace/ending_newline', 5,
2076 'Complex multi-line /*...*/-style comment found. '
2078 'Consider replacing these with //-style comments, '
2080 'or with more clearly structured multi-line comments.')
2082 if (line.count('"') - line.count('\\"')) % 2:
2084 'Multi-line string ("...") found. This lint script doesn\'t '
2089 # (non-threadsafe name, thread-safe alternative, validation pattern)
2093 # ->rand(); // some member function rand().
2101 _UNSAFE_FUNC_PREFIX = r'(?:[-+*/=%^&|(<]\s*|>\s+)'
2120 """Checks for calls to thread-unsafe functions.
2123 multi-threading. Also, engineers are relying on their old experience;
2125 tests guide the engineers to use thread-safe functions (when using
2166 r'^\s*\*\w+(\+\+|--);')
2195 if linenum > 0 and Search(r'\\$', clean_lines[linenum - 1]):
2290 depth += line.count('{') - line.count('}')
2304 for i in xrange(linenum - 1, self.starting_linenum, -1):
2320 # This means we will not check single-line class definitions.
2354 if (linenum - self.starting_linenum < 10
2413 # - _ClassInfo: a class or struct.
2414 # - _NamespaceInfo: a namespace.
2415 # - _BlockInfo: some other type of block.
2439 return (not self.stack) or self.stack[-1].seen_open_brace
2447 return self.stack and isinstance(self.stack[-1], _NamespaceInfo)
2455 return self.stack and isinstance(self.stack[-1], _ExternCInfo)
2463 return self.stack and isinstance(self.stack[-1], _ClassInfo)
2471 return self.stack and self.stack[-1].inline_asm != _NO_ASM
2517 (_, end_line, end_pos) = CloseExpression(clean_lines, linenum, pos - 1)
2536 - Preprocessor condition evaluates to true from #if up to first
2539 - Preprocessor condition evaluates to false from #else/#elif up
2553 if not self.pp_stack[-1].seen_else:
2557 self.pp_stack[-1].seen_else = True
2558 self.pp_stack[-1].stack_before_else = copy.deepcopy(self.stack)
2561 self.stack = copy.deepcopy(self.pp_stack[-1].stack_before_if)
2571 if self.pp_stack[-1].seen_else:
2574 self.stack = self.pp_stack[-1].stack_before_else
2599 self.previous_stack_top = self.stack[-1]
2609 inner_block = self.stack[-1]
2610 depth_change = line.count('(') - line.count(')')
2645 if line.find('{') != -1:
2656 r'(class|struct)\s+(?:[A-Z_]+\s+)*(\w+(?:::\w+)*))'
2659 (not self.stack or self.stack[-1].open_parentheses == 0)):
2679 self.stack[-1].CheckBegin(filename, clean_lines, linenum, error)
2682 if self.stack and isinstance(self.stack[-1], _ClassInfo):
2683 classinfo = self.stack[-1]
2720 self.stack[-1].seen_open_brace = True
2726 self.stack[-1].inline_asm = _BLOCK_ASM
2742 self.stack[-1].CheckEnd(filename, clean_lines, linenum, error)
2752 for i in range(len(self.stack), 0, -1):
2753 classinfo = self.stack[i - 1]
2782 r"""Logs an error if we see certain non-ANSI constructs ignored by gcc-2.
2784 Complain about several constructs which gcc-2 accepts, but which are
2787 - put storage class first (e.g. "static const" instead of "const static").
2788 - "%lld" instead of %qd" in printf-type functions.
2789 - "%1$d" is non-standard in printf-type functions.
2790 - "\%" is an undefined character escape sequence.
2791 - text after #endif is not allowed.
2792 - invalid inner-style forward declaration.
2793 - >? and <? operators, and their >?= and <?= cousins.
2797 gcc-2 compliance.
2812 if Search(r'printf\s*\(.*".*%[-+ ]?\d*q', line):
2836 'Storage-class specifier (static, extern, typedef, etc) should be '
2841 'Uncommented text after #endif is non-standard. Use a comment.')
2845 'Inner-style forward declarations are invalid. Remove this line.')
2847 if Search(r'(\w+|[+-]?\d+(\.\d*)?)\s*(<|>)\?=?\s*(\w+|[+-]?\d+)(\.\d*)?',
2850 '>? and <? (max and min) operators are non-standard and deprecated.')
2873 base_classname = classinfo.name.split('::')[-1]
2875 # Look for single-argument constructors that aren't marked explicit.
2914 len(defaulted_args) >= len(constructor_args) - 1))
2933 'Single-parameter constructors should be marked explicit.')
2937 'Zero-parameter constructors should not be marked explicit.')
2952 # expressions - which have their own, more liberal conventions - we
2973 # " (something)(maybe-something)" or
2974 # " (something)(maybe-something," or
3036 nesting_state.stack[-1].check_namespace_indentation and
3038 nesting_state.previous_stack_top == nesting_state.stack[-2])
3051 https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3079 function_name = match_result.group(1).split()[-1]
3081 not Match(r'[A-Z_]+$', function_name)):
3104 # No body for the function (or evidence of a non-function) was found.
3111 function_state.Count() # Count non-blank/non-comment lines.
3124 next_line_start: The first non-whitespace column of the next line.
3128 if commentpos != -1:
3134 line[commentpos-1] not in string.whitespace) or
3136 line[commentpos-2] not in string.whitespace))):
3157 # Comparisons made explicit for correctness -- pylint: disable=g-explicit-bool-comparison
3172 """Checks for the correctness of various spacing issues in the code.
3214 prev_line = elided[linenum - 1]
3220 if prevbrace != -1 and prev_line[prevbrace:].find('}') == -1:
3223 # non-empty line has the parameters of a function header that are indented
3232 search_position = linenum-2
3235 search_position -= 1
3253 # Ignore blank lines at the end of a block in a long if-else
3265 and next_line.find('} else ') == -1):
3279 next_line_start = len(next_line) - len(next_line.lstrip())
3291 # In range-based for, we wanted spaces before and after the colon, but
3296 'Missing space around colon in range-based for loop')
3323 # We allow no-spaces around = within an if: "if ( (a=Foo()) == 0 )".
3324 # Otherwise not. Note we only check for non-spaces on *both* sides;
3325 # sometimes people put non-spaces on one side when aligning ='s among
3336 # It's ok not to have spaces around binary operators like + - * /, but if
3343 # check non-include lines for spacing around < and >.
3364 if end_pos <= -1:
3371 match = Match(r'^(.*[^-\s>])>[^\s=>,]', line)
3375 if start_pos <= -1:
3379 # We allow no-spaces around << when used like this: 10<<20, but
3390 # We allow no-spaces around >> for almost anything. This is because
3391 # C++11 allows ">>" to close nested templates, which accounts for
3398 # When ">>" is used to close templates, the alphanumeric letter that
3402 match = Search(r'>>[a-zA-Z_]', line)
3408 match = Search(r'(!\s|~\s|[\s]--[\s;]|[\s]\+\+[\s;])', line)
3466 # This does not apply when the non-space character following the
3515 block_index = len(nesting_state.stack) - 1
3530 next_block_start = nesting_state.stack[block_index - 1].starting_linenum
3535 first_line -= 1
3539 block_index -= 1
3546 block_index -= 1
3605 if endpos > -1:
3608 min(endlinenum + 3, clean_lines.NumLines() - 1)):
3659 """Checks for additional blank line issues related to sections.
3681 if (class_info.last_line - class_info.starting_linenum <= 24 or
3690 # - We are at the beginning of the class.
3691 # - We are forward-declaring an inner class that is semantically
3695 prev_line = clean_lines.lines[linenum - 1]
3700 # account for multi-line base-specifier lists, e.g.:
3708 if end_class_head < linenum - 1:
3714 """Return the most recent non-blank line and its line number.
3722 non-blank line before the current line, or the empty string if this is the
3723 first non-blank line. The second is the line number of that line, or -1
3724 if this is the first non-blank line.
3727 prevlinenum = linenum - 1
3732 prevlinenum -= 1
3733 return ('', -1)
3751 # to control the lifetime of stack-allocated variables. Braces are also
3753 # perfectly: we just don't complain if the last non-whitespace character on
3754 # the previous non-blank line is ',', ';', ':', '(', '{', or '}', or if the
3761 not (GetLineWidth(prevline) > _line_length - 2 and '[]' in prevline)):
3774 if Search(r'else if\s*\(', line): # could be multi-line if
3781 brace_on_right = endline[endpos:].find('{') != -1
3799 # Check single-line if/else bodies. The style guide says 'curly braces are not
3800 # required for single-line statements'. We additionally allow multi-line,
3813 pos = if_match.end() - 1
3816 # line. If found, this isn't a single-statement conditional.
3819 and endlinenum < (len(clean_lines.elided) - 1)
3827 # We allow a mix of whitespace and closing braces (e.g. for one-liner
3838 elif endlinenum < len(clean_lines.elided) - 1:
3896 # braces inside multi-dimensional arrays, but this is fine since
3916 # - macro that defines a base class
3917 # - multi-line macro that defines a base class
3918 # - macro that defines the whole class-head
3922 # - TEST, TEST_F, TEST_P, MATCHER, MATCHER_P
3923 # - TYPED_TEST
3924 # - INTERFACE_DEF
3925 # - EXCLUSIVE_LOCKS_REQUIRED, SHARED_LOCKS_REQUIRED, LOCKS_EXCLUDED:
3935 # - Compound literals
3936 # - Lambdas
3937 # - alignas specifier with anonymous structs
3938 # - decltype
3942 if opening_parenthesis[2] > -1:
3944 macro = Search(r'\b([A-Z_][A-Z0-9_]*)\s*$', line_prefix)
3958 Search(r'\]\s*$', clean_lines.elided[opening_parenthesis[1] - 1])):
3959 # Multi-line lambda-expression
3963 # Try matching cases 2-3.
3966 # Try matching cases 4-6. These are always matched on separate lines.
3982 if endpos > -1 and Match(r'^\s*;', endline[endpos:]):
3993 ParseNolintSuppressions(filename, raw_lines[endlinenum-1], endlinenum-1,
4014 # do-while-loops, since those lines should start with closing brace.
4079 body.append(clean_lines.elided[closing_linenum][:closing_pos-1])
4083 body = opening_line[opening_pos+1:closing_pos-1]
4107 """Find a replaceable CHECK-like macro.
4112 (macro name, start position), or (None, -1) if no replaceable
4126 return (None, -1)
4158 expression = lines[linenum][start_pos + 1:end_pos - 1]
4163 expression += last_line[0:end_pos - 1]
4172 matched = Match(r'^\s*(<<|<<=|>>|>>=|->\*|->|&&|\|\||'
4191 elif token in ('<<', '<<=', '>>', '>>=', '->*', '->'):
4192 # Non-relational operator
4206 matched = Match(r'^([^-=!<>()&|]+)(.*)$', expression)
4220 if rhs.find('&&') > -1 or rhs.find('||') > -1:
4231 match_constant = r'^([-+]?(\d+|0[xX][0-9a-fA-F]+)[lLuU]{0,3}|".*"|\'.*\')$'
4262 # Last ditch effort to avoid multi-line comments. This will not help
4266 # multi-line comments in preprocessor macros.
4269 # multi-line comments.
4296 # https://mail.python.org/pipermail/python-list/2012-August/628809.html
4304 width -= 1
4306 # Android prebuilt python ends up CHECK-failing here due to how it's compiled.
4319 do what we can. In particular we check for 2-space indents, line lengths,
4337 prev = raw_lines[linenum - 1] if linenum > 0 else ''
4339 if line.find('\t') != -1:
4344 # hard to reconcile that with 2-space indents.
4362 # section labels, and also lines containing multi-line raw strings.
4365 # because the rules for how to indent those are non-trivial.
4372 'Weird number of spaces at line-start. '
4373 'Are you using a 2-space indent?')
4375 if line and line[-1].isspace():
4398 not Match(r'^// \$Id:.*#[0-9]+ \$$', line)):
4406 cleansed_line.find('for') == -1 and
4407 (GetPreviousNonBlankLine(clean_lines, linenum)[0].find('for') == -1 or
4408 GetPreviousNonBlankLine(clean_lines, linenum)[0].find(';') != -1) and
4410 not ((cleansed_line.find('case ') != -1 or
4411 cleansed_line.find('default:') != -1) and
4412 cleansed_line.find('break;') != -1)):
4434 # Matches the first component of a filename delimited by -s and _s. That is:
4437 # _RE_FIRST_COMPONENT.match('foo-bar_baz.cc').group(0) == 'foo'
4438 # _RE_FIRST_COMPONENT.match('foo_bar-baz.cc').group(0) == 'foo'
4439 _RE_FIRST_COMPONENT = re.compile(r'^[^-_.]+')
4443 """Drops common suffixes like _test.cc or -inl.h from filename.
4446 >>> _DropCommonSuffixes('foo/foo-inl.h')
4464 filename[-len(suffix) - 1] in ('-', '_')):
4465 return filename[:-len(suffix) - 1]
4575 include_state.include_list[-1].append((include, linenum))
4604 r"""Retrieves all the text between matching open and close parentheses.
4608 (, [, or {, and the matching close-punctuation symbol. This properly nested
4626 # Give opening punctuations to get the matching close-punctuations.
4638 assert text[start_position - 1] in matching_punctuation, (
4641 punctuation_stack = [matching_punctuation[text[start_position - 1]]]
4644 if text[position] == punctuation_stack[-1]:
4653 # Opening punctuations left without matching close-punctuations.
4656 return text[start_position:position - 1]
4659 # Patterns for matching call-by-reference parameters.
4668 _RE_PATTERN_IDENT = r'[_a-zA-Z]\w*' # =~ [[:alpha:]][[:alnum:]]*
4674 # A call-by-reference parameter ends with '& identifier'.
4678 # A call-by-const-reference parameter either ends with 'const& identifier'
4731 # TODO(unknown): check that 1-arg constructors are explicit.
4734 # TODO(unknown): check that classes declare or disable copy/assign
4751 # TODO(unknown): catch out-of-line unary operator&:
4768 # Not perfect but it can catch printf(foo.c_str()) and printf(foo->c_str())
4775 match = Match(r'([\w.\->()]+)$', printf_args)
4785 if match and not Match(r"^''|-?[0-9]+|0x[0-9A-Fa-f]$", match.group(2)):
4792 'Do not use namespace using-directives. '
4793 'Use using-declarations instead.')
4795 # Detect variable-length arrays.
4796 match = Match(r'\s*(.+::)?(\w+) [a-z]\w*\[(.+)];', line)
4798 match.group(3).find(']') == -1):
4802 tokens = re.split(r'\s|\+|\-|\*|\/|<<|>>]', match.group(3))
4817 if Match(r'0[xX][0-9a-fA-F]+', tok): continue
4818 if Match(r'k[A-Z0-9]\w*', tok): continue
4819 if Match(r'(.+::)?k[A-Z0-9]\w*', tok): continue
4820 if Match(r'(.+::)?[A-Z][A-Z0-9_]*', tok): continue
4831 'Do not use variable-length arrays. Use an appropriately named '
4832 "('k' followed by CamelCase) compile-time constant for the size.")
4839 and line[-1] != '\\'):
4842 'https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces'
4866 # TODO(unknown): File bugs for clang-tidy to find these.
4869 r'([a-zA-Z0-9_:]+)\b(.*)',
4873 # - String pointers (as opposed to values).
4879 # - Functions and template specializations.
4883 # - Operators. These are matched separately because operator names
4884 # cross non-word boundaries, and trying to match both operators
4891 not Match(r'\s*(<.*>)?(::[a-zA-Z0-9_]+)*\s*\(([^"]|$)', match.group(4))):
4901 if (Search(r'\b([A-Za-z0-9_]*_)\(\1\)', line) or
4902 Search(r'\b([A-Za-z0-9_]*_)\(CHECK_NOTNULL\(\1\)\)', line)):
4908 """Check for printf related issues.
4919 match = Search(r'snprintf\s*\(([^,]*),\s*([0-9]*)\s*,', line)
4944 virt-specifier.
4947 for i in xrange(linenum, max(-1, linenum - 10), -1):
4959 """Check if current line contains an out-of-line method definition.
4965 True if current line contains an out-of-line method definition.
4968 for i in xrange(linenum, max(-1, linenum - 10), -1):
4984 for i in xrange(linenum, 1, -1):
4999 # brace-initialized member in constructor initializer list.
5003 # - A closing brace or semicolon, probably the end of the previous
5005 # - An opening brace, probably the start of current class or namespace.
5018 """Check for non-const references.
5037 # a choice, so any non-const references should not be blamed on
5042 # Don't warn on out-of-line method definitions, as we would warn on the
5043 # in-line declaration, if it isn't marked with 'override'.
5068 clean_lines.elided[linenum - 1])
5069 elif Match(r'\s*[a-zA-Z_]([\w<>]|::)+\s*&\s*\S', line):
5072 clean_lines.elided[linenum - 1])
5078 if endpos > -1:
5081 if startpos > -1 and startline < linenum:
5088 # Check for non-const references in function parameters. A single '&' may
5109 for i in xrange(linenum - 1, max(0, linenum - 10), -1):
5124 # We allow non-const references in a few standard places, like functions
5139 # multi-line parameter list. Try a bit harder to catch this case.
5142 Search(whitelisted_functions, clean_lines.elided[linenum - i - 1])):
5150 'Is this a non-const reference? '
5179 # - New operators
5180 # - Template arguments with function types
5185 # template argument. False negative with less-than comparison is
5198 # - Function pointers
5199 # - Casts to pointer types
5200 # - Placement new
5201 # - Alias declarations
5232 # is dangerous -- casts can assign to temporaries, so the pointer doesn't
5235 # Some non-identifier character is required before the '&' for the
5257 if y2 < clean_lines.NumLines() - 1:
5259 if Match(r'\s*(?:->|\[)', extended_line):
5275 """Checks for a C-style cast by looking for the pattern.
5283 pattern: The regular expression used to find C-style casts.
5296 context = line[0:match.start(1) - 1]
5297 if Match(r'.*\b(?:sizeof|alignof|alignas|[_A-Z][_A-Z0-9]*)\s*$', context):
5303 for i in xrange(linenum - 1, max(0, linenum - 5), -1):
5305 if Match(r'.*\b[_A-Z][_A-Z0-9]*\s*\((?:\([^()]*\)|[^()])*$', context):
5308 # operator++(int) and operator--(int)
5309 if context.endswith(' operator++') or context.endswith(' operator--'):
5315 if Match(r'^\s*(?:;|const\b|throw\b|final\b|override\b|[=>{),]|->)',
5321 'Using C-style cast. Use %s<%s>(...) instead' %
5342 clean_lines.elided[linenum - 1]) or
5344 clean_lines.elided[linenum - 2]) or
5346 clean_lines.elided[linenum - 1]))))
5402 # Match max<type>(..., ...), max(..., ...), but not foo->max, foo.max or
5423 foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the
5452 filename_cc = filename_cc[:-len(fileinfo.Extension())]
5455 filename_cc = filename_cc[:-len(matched_test_suffix.group(1))]
5461 filename_h = filename_h[:-len('.h')]
5462 if filename_h.endswith('-inl'):
5463 filename_h = filename_h[:-len('-inl')]
5470 common_path = filename_cc[:-len(filename_h)]
5527 # String is special -- it is a non-templatized type in STL.
5530 # Don't warn about strings in non-STL namespaces:
5547 # Don't warn about IWYU in non-STL namespaces:
5620 'For C++11-compatibility, omit template arguments from make_pair'
5625 """Check if line contains a redundant "virtual" function-specifier.
5638 # Ignore "virtual" keywords that are near access-specifiers. These
5639 # are only used in class base-specifier and do not apply to member
5655 end_col = -1
5656 end_line = -1
5689 """Check if line contains a redundant "override" or "final" virt-specifier.
5698 # the declarator ends and where the virt-specifier starts to avoid
5705 if linenum > 1 and clean_lines.elided[linenum - 1].rfind(')') >= 0:
5732 isinstance(nesting_state.stack[-1], _NamespaceInfo)):
5738 nesting_state.stack[-1].check_namespace_indentation and
5739 isinstance(nesting_state.stack[-2], _NamespaceInfo))
5874 ('std::%s is an unapproved C++11 class or function. Send c-style '
5997 # Suppress "Ignoring file" warning when using --quiet.
6026 # Apply all the accumulated filters in reverse order (top-level directory
6035 """Does google-lint on a single file.
6059 # Support the UNIX convention of using "-" for stdin. Note that
6066 if filename == '-':
6075 # The -1 accounts for the extra trailing blank line we get from split()
6076 for linenum in range(len(lines) - 1):
6094 if filename != '-' and file_extension not in _valid_extensions:
6101 # If end-of-line sequences are a mix of LF and CR-LF, issue
6104 # Don't issue any warnings if all lines are uniformly LF or CR-LF,
6109 # end-of-line sequence should be, since that will return the
6110 # server-side end-of-line sequence.
6119 # Suppress printing anything if --quiet was passed unless the error
6140 """Prints a list of all the error-categories used by error messages.
6142 These are the categories used to filter messages via --filter.
6151 This may set the output format and verbosity level as side-effects.
6178 if opt == '--help':
6180 elif opt == '--output':
6184 elif opt == '--quiet':
6186 elif opt == '--verbose':
6188 elif opt == '--filter':
6192 elif opt == '--counting':
6196 elif opt == '--root':
6199 elif opt == '--linelength':
6205 elif opt == '--extensions':
6211 elif opt == '--headers':
6230 # if we try to print something containing non-ASCII characters.
6239 # If --quiet is passed, suppress printing error count unless there are errors.