clint: Add diagnostics for things like char* foo or (char*)

Asterisk should be preceded by a space except the following cases:

1. `foo[*idx_ptr]`
2. `++*foo` (though I would prefer to write this as `++(*foo)`)
3. `(*foo)->bar`, `if (*p)`
4. `char **foo`
5. `/* comment */`
6. `!*p`

Note: `[^ (*/![]` is followed by `+` to make error position easier to find. It
is not needed to find location of the problem.
This commit is contained in:
ZyX 2016-04-13 02:40:41 +03:00
parent f47a20a266
commit 0cb2c39ec4

View File

@ -2291,6 +2291,11 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
# there's too little whitespace, we get concerned. It's hard to tell,
# though, so we punt on this one for now. TODO.
match = Search(r'(?:[^ (*/![])+(?<!\+\+|--)\*', line)
if match:
error(filename, linenum, 'whitespace/operators', 2,
'Missing space before asterisk in %s' % match.group(0))
# You should always have whitespace around binary operators.
#
# Check <= and >= first to avoid false positives with < and >, then