@@ -326,3 +326,20 @@ try_checkpatch \
"
AT_CLEANUP
+
+AT_SETUP([checkpatch - whitespace around cast])
+try_checkpatch \
+ "COMMON_PATCH_HEADER
+ + (int) a;
+ "
+
+try_checkpatch \
+ "COMMON_PATCH_HEADER
+ + (int)a;
+ " \
+ "ERROR: Inappropriate spacing around cast
+ #8 FILE: A.c:1:
+ (int)a;
+"
+
+AT_CLEANUP
@@ -167,6 +167,7 @@ __regex_is_for_if_single_line_bracket = \
__regex_ends_with_bracket = \
re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$')
__regex_ptr_declaration_missing_whitespace = re.compile(r'[a-zA-Z0-9]\*[^*]')
+__regex_cast_missing_whitespace = re.compile(r'\)[a-zA-Z0-9]')
__regex_is_comment_line = re.compile(r'^\s*(/\*|\*\s)')
__regex_has_comment = re.compile(r'.*(/\*|\*\s)')
__regex_has_c99_comment = re.compile(r'.*//.*$')
@@ -286,6 +287,12 @@ def pointer_whitespace_check(line):
return __regex_ptr_declaration_missing_whitespace.search(line) is not None
+def cast_whitespace_check(line):
+ """Return TRUE if there is no space between the '()' used in a cast and
+ the expression whose type is cast, i.e.: '(void *)foo'"""
+ return __regex_cast_missing_whitespace.search(line) is not None
+
+
def line_length_check(line):
"""Return TRUE if the line length is too long"""
if len(line) > 79:
@@ -551,6 +558,12 @@ checks = [
'print':
lambda: print_error("Inappropriate spacing in pointer declaration")},
+ {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None,
+ 'prereq': lambda x: not is_comment_line(x),
+ 'check': lambda x: cast_whitespace_check(x),
+ 'print':
+ lambda: print_error("Inappropriate spacing around cast")},
+
{'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None,
'prereq': lambda x: not is_comment_line(x),
'check': lambda x: trailing_operator(x),
Coding style says: "Put a space between the ``()`` used in a cast and the expression whose type is cast: ``(void *) 0``.". This style rule is frequently overlooked. Let's check for it. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> --- tests/checkpatch.at | 17 +++++++++++++++++ utilities/checkpatch.py | 13 +++++++++++++ 2 files changed, 30 insertions(+)