Skip to content

Commit d590db4

Browse files
thk123tautschnig
thk123
authored andcommitted
Don't think function declarations should have function header comments
Previously we would always checkf for function header comments if we found a function. Now if we find a ; before a { then we assume it is a function declaration, otherwise we assume it is a function implementation and therefore should have the function header comment. This does mean that functions with bodies in header files are going to require a function header comment.
1 parent 7374c77 commit d590db4

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*******************************************************************\
2+
3+
Module: Lint Examples
4+
5+
Author: Thomas Kiley, [email protected]
6+
7+
\*******************************************************************/
8+
9+
10+
11+
static void fun(
12+
bool param1,
13+
bool param2);
14+
15+
static void bar();
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

+7-18
Original file line numberDiff line numberDiff line change
@@ -3120,26 +3120,15 @@ def CheckForFunctionCommentHeaders(filename, raw_lines, error):
31203120
body_found = False
31213121
for start_linenum in xrange(linenum, len(raw_lines)):
31223122
start_line = raw_lines[start_linenum]
3123-
joined_line += ' ' + start_line.lstrip()
3124-
if Search(r'(;|})', start_line): # Declarations and trivial functions
3123+
if Search(r'{', start_line):
31253124
body_found = True
3126-
break # ... ignore
3127-
elif Search(r'{', start_line):
3128-
body_found = True
3129-
function = Search(r'((\w|:)*)\(', line).group(1)
3130-
if Match(r'TEST', function): # Handle TEST... macros
3131-
parameter_regexp = Search(r'(\(.*\))', joined_line)
3132-
if parameter_regexp: # Ignore bad syntax
3133-
function += parameter_regexp.group(1)
3134-
else:
3135-
function += '()'
3136-
function_state.Begin(function)
31373125
break
3138-
if not body_found:
3139-
# No body for the function (or evidence of a non-function) was found.
3140-
error(filename, linenum, 'readability/fn_size', 5,
3141-
'Lint failed to find start of function body.')
3142-
else:
3126+
elif Search(r';', start_line):
3127+
body_found = False
3128+
break
3129+
3130+
# body found, i.e. not a declaration
3131+
if body_found:
31433132
CheckForFunctionCommentHeader(filename, raw_lines, linenum, function_name, error)
31443133
linenum += 1
31453134

0 commit comments

Comments
 (0)