Skip to content

Commit

Permalink
Don't think function declarations should have function header comments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thk123 authored and tautschnig committed Dec 23, 2016
1 parent 7374c77 commit d590db4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
15 changes: 15 additions & 0 deletions regression/cpp-linter/function-comment-header7/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*******************************************************************\
Module: Lint Examples
Author: Thomas Kiley, [email protected]
\*******************************************************************/



static void fun(
bool param1,
bool param2);

static void bar();
7 changes: 7 additions & 0 deletions regression/cpp-linter/function-comment-header7/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$
--
25 changes: 7 additions & 18 deletions scripts/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3120,26 +3120,15 @@ def CheckForFunctionCommentHeaders(filename, raw_lines, error):
body_found = False
for start_linenum in xrange(linenum, len(raw_lines)):
start_line = raw_lines[start_linenum]
joined_line += ' ' + start_line.lstrip()
if Search(r'(;|})', start_line): # Declarations and trivial functions
if Search(r'{', start_line):
body_found = True
break # ... ignore
elif Search(r'{', start_line):
body_found = True
function = Search(r'((\w|:)*)\(', line).group(1)
if Match(r'TEST', function): # Handle TEST... macros
parameter_regexp = Search(r'(\(.*\))', joined_line)
if parameter_regexp: # Ignore bad syntax
function += parameter_regexp.group(1)
else:
function += '()'
function_state.Begin(function)
break
if not body_found:
# No body for the function (or evidence of a non-function) was found.
error(filename, linenum, 'readability/fn_size', 5,
'Lint failed to find start of function body.')
else:
elif Search(r';', start_line):
body_found = False
break

# body found, i.e. not a declaration
if body_found:
CheckForFunctionCommentHeader(filename, raw_lines, linenum, function_name, error)
linenum += 1

Expand Down

0 comments on commit d590db4

Please sign in to comment.