From 0075d1469a7b1aca881f7750c526691279a20db8 Mon Sep 17 00:00:00 2001 From: "erg@google.com" Date: Tue, 5 Nov 2013 22:28:07 +0000 Subject: [PATCH] A false positive occurs when a user specifies a using declaration for 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 . --- cpplint/cpplint.py | 7 +++++-- cpplint/cpplint_unittest.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 7ca3862..b5493b6 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -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): diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index e7e5744..78d2c13 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -1562,6 +1562,8 @@ class CpplintTest(CpplintTestBase): '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)', '')