Skip to content

Commit 7638907

Browse files
thk123tautschnig
thk123
authored andcommitted
Don't include * or & in function name
When checking for function comments we don't want to include the * or & in the name. Instead we allow after the space of the return type an optional * or & before accepting the function name.
1 parent fa53b71 commit 7638907

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
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: fun
12+
13+
Inputs:
14+
15+
Outputs:
16+
17+
Purpose:
18+
19+
\*******************************************************************/
20+
21+
static int *fun()
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -3097,12 +3097,14 @@ def CheckForFunctionCommentHeaders(filename, raw_lines, error):
30973097
for line in raw_lines:
30983098
joined_line = ''
30993099
starting_func = False
3100-
regexp = r'(\w(\w|::|\*|\&|\s)*)\(' # decls * & space::name( ...
3100+
# Look for declaration function_name( but allowing for *, & being attached to the function name
3101+
# but not being considered part of it
3102+
regexp = r'\w(\w|::|\s|\*|\&)* (\*|\&)?(?P<fnc_name>\w(\w|::)*)\('
31013103
match_result = Match(regexp, line)
31023104
if match_result:
31033105
# If the name is all caps and underscores, figure it's a macro and
31043106
# ignore it, unless it's TEST or TEST_F.
3105-
function_name = match_result.group(1).split()[-1]
3107+
function_name = match_result.group('fnc_name')
31063108
if function_name == 'TEST' or function_name == 'TEST_F' or (
31073109
not Match(r'[A-Z_]+$', function_name)):
31083110
starting_func = True

0 commit comments

Comments
 (0)