Skip to content

Commit

Permalink
A false positive occurs when a user specifies a using declaration for…
Browse files Browse the repository at this point in the history
… a stream operator:

    10: using ns::operator<<;
    file.cpp:10: Missing spaces around << [whitespace/operators] [3]

The regular expression has been updated to find this valid use case of the <<
text string.

Review URL: https://codereview.appspot.com/22190043

Patch from Matt Clarkson <[email protected]>.
  • Loading branch information
[email protected] committed Nov 5, 2013
1 parent ab53edf commit 0075d14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cpplint/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,8 +2681,11 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
'Missing spaces around %s' % match.group(1))
# We allow no-spaces around << when used like this: 10<<20, but
# not otherwise (particularly, not when used as streams)
match = Search(r'(\S)(?:L|UL|ULL|l|ul|ull)?<<(\S)', line)
if match and not (match.group(1).isdigit() and match.group(2).isdigit()):
# Also ignore using ns::operator<<;
match = Search(r'(operator|\S)(?:L|UL|ULL|l|ul|ull)?<<(\S)', line)
if (match and
not (match.group(1).isdigit() and match.group(2).isdigit()) and
not (match.group(1) == 'operator' and match.group(2) == ';')):
error(filename, linenum, 'whitespace/operators', 3,
'Missing spaces around <<')
elif not Match(r'#.*include', line):
Expand Down
2 changes: 2 additions & 0 deletions cpplint/cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,8 @@ def testCheckCheck(self):
'Consider using CHECK_GT instead of CHECK(a > b)'
' [readability/check] [2]'])

self.TestLint('using some::namespace::operator<<;', '')
self.TestLint('using some::namespace::operator>>;', '')
self.TestLint('CHECK(x ^ (y < 42))', '')
self.TestLint('CHECK((x > 42) ^ (x < 54))', '')
self.TestLint('CHECK(a && b < 42)', '')
Expand Down

0 comments on commit 0075d14

Please sign in to comment.