diff --git a/cpplint.py b/cpplint.py index 514d6f6..7ccdda0 100644 --- a/cpplint.py +++ b/cpplint.py @@ -2470,7 +2470,7 @@ def Update(self, filename, clean_lines, linenum, error): # class LOCKABLE API Object { # }; class_decl_match = Match( - r'^(\s*(?:template\s*<[\w\s<>,:]*>\s*)?' + r'^(\s*(?:template\s*<[\w\s<>,:=]*>\s*)?' r'(class|struct)\s+(?:[A-Z_]+\s+)*(\w+(?:::\w+)*))' r'(.*)$', line) if (class_decl_match and @@ -3541,7 +3541,7 @@ def IsRValueType(typenames, clean_lines, nesting_state, linenum, column): # We want to skip over identifiers and commas to get to a symbol. # Commas are skipped so that we can find the opening parenthesis # for function parameter lists. - match_symbol = Match(r'^(.*)([^\w\s,])[\w\s,]*$', line) + match_symbol = Match(r'^(.*)([^\w\s,:&*])[\w\s,:&*]*$', line) if match_symbol: break start -= 1 diff --git a/cpplint_unittest.py b/cpplint_unittest.py index e48e986..e6a923c 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -1006,6 +1006,22 @@ def testCleanseLine(self): cpplint.CleanseComments('f(a, /**/b/**/, c);')) def testRawStrings(self): + self.TestMultiLineLint( + """ + int main() { + struct A { + A(std::string s, A&& a); + }; + }""", + 'RValue references are an unapproved C++ feature. [build/c++11] [3]') + + self.TestMultiLineLint( + """ + template > class unique_ptr { + public: + unique_ptr(unique_ptr&& u) noexcept; + };""", + 'RValue references are an unapproved C++ feature. [build/c++11] [3]') self.TestMultiLineLint( """ void Func() { @@ -2577,6 +2593,11 @@ def testRvalueReference(self): self.TestLint('const a&& b = c;', rvalue_error) self.TestLint('struct a&& b = c;', rvalue_error) self.TestLint('decltype(a)&& b = c;', rvalue_error) + self.TestLint('A(int s, A&& a);', rvalue_error) + self.TestLint('A(std::string s, A&& a);', rvalue_error) + self.TestLint('A(const std::string &s, A&& a);', rvalue_error) + self.TestLint('A(int* s, A&& a);', rvalue_error) + self.TestLint('unique_ptr(unique_ptr&& u) noexcept;', rvalue_error) # Cast expressions self.TestLint('a = const_cast(c);', rvalue_error) @@ -5440,6 +5461,12 @@ def testTemplate(self): self.assertTrue(isinstance(self.nesting_state.stack[0], cpplint._ClassInfo)) self.assertEquals(self.nesting_state.stack[0].name, 'K') + def testTemplateDefaultArg(self): + self.UpdateWithLines([ + 'template > class unique_ptr {',]) + self.assertEquals(len(self.nesting_state.stack), 1) + self.assertTrue(self.nesting_state.stack[0], isinstance(self.nesting_state.stack[0], cpplint._ClassInfo)) + def testTemplateInnerClass(self): self.UpdateWithLines(['class A {', ' public:'])