Skip to content

Commit 7374c77

Browse files
thk123tautschnig
thk123
authored andcommitted
Handle operator functions when looking for function comment headers
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.
1 parent 7638907 commit 7374c77

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*******************************************************************\
2+
3+
Module: Lint Examples
4+
5+
Author: Thomas Kiley, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/*******************************************************************\
10+
11+
Function: operator()
12+
13+
Inputs:
14+
15+
Outputs:
16+
17+
Purpose:
18+
19+
\*******************************************************************/
20+
21+
static void operator()()
22+
{
23+
do_something();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.cpp
3+
4+
^Total errors found: 0$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--

scripts/cpplint.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -3099,12 +3099,19 @@ def CheckForFunctionCommentHeaders(filename, raw_lines, error):
30993099
starting_func = False
31003100
# Look for declaration function_name( but allowing for *, & being attached to the function name
31013101
# but not being considered part of it
3102-
regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>\w(\w|::)*)\('
3102+
regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>(\w(\w|::)*))\('#
3103+
operator_regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>(|operator\(.*\)|operator.*))\('
3104+
operator_match = Match(operator_regexp, line)
31033105
match_result = Match(regexp, line)
3104-
if match_result:
3106+
function_name = ""
3107+
if operator_match:
3108+
function_name = operator_match.group('fnc_name')
3109+
elif match_result:
3110+
function_name = match_result.group('fnc_name')
3111+
3112+
if operator_match or match_result:
31053113
# If the name is all caps and underscores, figure it's a macro and
31063114
# ignore it, unless it's TEST or TEST_F.
3107-
function_name = match_result.group('fnc_name')
31083115
if function_name == 'TEST' or function_name == 'TEST_F' or (
31093116
not Match(r'[A-Z_]+$', function_name)):
31103117
starting_func = True
@@ -3157,6 +3164,8 @@ def CheckForFunctionCommentHeader(filename, raw_lines, linenum, function_name, e
31573164
31583165
"""
31593166

3167+
function_name = re.escape(function_name)
3168+
31603169
header_top_regex = r'^/\*{67}\\$'
31613170
header_bottom_regex = r'^\\\*{67}/$'
31623171
function_name_regex = r'Function: (\w+::)?' + function_name+'$'

0 commit comments

Comments
 (0)