Skip to content

Commit

Permalink
Handle operator functions when looking for function comment headers
Browse files Browse the repository at this point in the history
Since operator functions can have non-word characters as part of their
name (specifically, can have an opening bracket) we deal with these
seperately in the explicit case where the functions name is operator.

Since the function name can now contain non-word characters (e.g. an
opening bracket) we must escape it before using it in the regex.
  • Loading branch information
thk123 authored and tautschnig committed Dec 23, 2016
1 parent 7638907 commit 7374c77
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
24 changes: 24 additions & 0 deletions regression/cpp-linter/function-comment-header6/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************\
Module: Lint Examples
Author: Thomas Kiley, [email protected]
\*******************************************************************/

/*******************************************************************\
Function: operator()
Inputs:
Outputs:
Purpose:
\*******************************************************************/

static void operator()()
{
do_something();
}
7 changes: 7 additions & 0 deletions regression/cpp-linter/function-comment-header6/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.cpp

^Total errors found: 0$
^EXIT=0$
^SIGNAL=0$
--
15 changes: 12 additions & 3 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3099,12 +3099,19 @@ def CheckForFunctionCommentHeaders(filename, raw_lines, error):
starting_func = False
# Look for declaration function_name( but allowing for *, & being attached to the function name
# but not being considered part of it
regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>\w(\w|::)*)\('
regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>(\w(\w|::)*))\('#
operator_regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>(|operator\(.*\)|operator.*))\('
operator_match = Match(operator_regexp, line)
match_result = Match(regexp, line)
if match_result:
function_name = ""
if operator_match:
function_name = operator_match.group('fnc_name')
elif match_result:
function_name = match_result.group('fnc_name')

if operator_match or match_result:
# If the name is all caps and underscores, figure it's a macro and
# ignore it, unless it's TEST or TEST_F.
function_name = match_result.group('fnc_name')
if function_name == 'TEST' or function_name == 'TEST_F' or (
not Match(r'[A-Z_]+$', function_name)):
starting_func = True
Expand Down Expand Up @@ -3157,6 +3164,8 @@ def CheckForFunctionCommentHeader(filename, raw_lines, linenum, function_name, e
"""

function_name = re.escape(function_name)

header_top_regex = r'^/\*{67}\\$'
header_bottom_regex = r'^\\\*{67}/$'
function_name_regex = r'Function: (\w+::)?' + function_name+'$'
Expand Down

0 comments on commit 7374c77

Please sign in to comment.