Don't warn about spacing around << as difficult to know if we should

Since we can't in general (without type analysis I think) tell the
difference between a bit shift operator << and a stream manipulator <<
we don't warn about it. In some instances we can tell if it is a stream
manipulator so we check for spaces there. I've added a known bug
operator-spacing3 that would be the perfect report of errors.
This commit is contained in:
thk123 2016-12-20 18:30:24 +00:00 committed by Michael Tautschnig
parent 76193a2a23
commit 60cb406822
5 changed files with 55 additions and 1 deletions

View File

@ -0,0 +1,19 @@
/*******************************************************************\
Module: Lint Examples
Author: Thomas Kiley, thomas@diffblue.com
\*******************************************************************/
static void fun()
{
status() << "Adding CPROVER library (" << eom;
int x = 1<<4;
status()<<"Adding CPROVER library ("<<eom;
// Ideally this should produce an error, see operator-spacing3
int x = 1 << 4;
}

View File

@ -0,0 +1,7 @@
CORE
main.cpp
^main\.cpp:15: Missing spaces around << \[whitespace/operators\] \[3\]
^Total errors found: 1$
^SIGNAL=0$
--

View File

@ -0,0 +1,18 @@
/*******************************************************************\
Module: Lint Examples
Author: Thomas Kiley, thomas@diffblue.com
\*******************************************************************/
static void fun()
{
status() << "Adding CPROVER library (" << eom;
int x = 1<<4;
status()<<"Adding CPROVER library ("<<eom;
int x = 1 << 4;
}

View File

@ -0,0 +1,10 @@
KNOWNBUG
main.cpp
^main\.cpp:15: Missing spaces around << \[whitespace/operators\] \[3\]
^main\.cpp:15: Missing spaces around << \[whitespace/operators\] \[3\]
^main\.cpp:17: Remove spaces around << \[whitespace/operators\] \[4\]
^main\.cpp:17: Remove spaces around << \[whitespace/operators\] \[4\]
^Total errors found: 4$
^SIGNAL=0$
--

2
scripts/cpplint.py vendored
View File

@ -3464,7 +3464,7 @@ def CheckOperatorSpacing(filename, clean_lines, linenum, error):
# Note that && is not included here. This is because there are too
# many false positives due to RValue references.
# match = Search(r'[^<>=!\s](==|!=|<=|>=|\|\|)[^<>=!\s,;\)]', line)
match = Search(r'[^\s](<<|&&|\|\|)[^\s]', line)
match = Search(r'[^\s](&&|\|\|)[^\s]', line)
if match:
error(filename, linenum, 'whitespace/operators', 3,
'Missing spaces around %s' % match.group(1))