diff --git a/cpplint.py b/cpplint.py index 128bb3c..8e547aa 100755 --- a/cpplint.py +++ b/cpplint.py @@ -6720,7 +6720,7 @@ def CheckCasts(filename, clean_lines, linenum, error): else: # Check pointer casts for other than string constants CheckCStyleCast( - filename, clean_lines, linenum, "reinterpret_cast", r"\((\w+\s?\*+\s?)\)", error + filename, clean_lines, linenum, "reinterpret_cast", r"(?{),]|->)", remainder): + if re.match(r"^\s*(?:;|(?:const|throw|final|override)\b|[=>{),]|->)", remainder): return False # At this point, all that should be left is actual casts. diff --git a/cpplint_unittest.py b/cpplint_unittest.py index 7b39074..ee9c7b4 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -1050,18 +1050,21 @@ def testDeprecatedCast(self): "Use static_cast(...) instead" " [readability/casting] [4]", ) - self.TestLint( '(char *) "foo"', "Using C-style cast. Use const_cast(...) instead [readability/casting] [4]", ) - self.TestLint( "(int*)foo", "Using C-style cast. " "Use reinterpret_cast(...) instead" " [readability/casting] [4]", ) + self.TestLint( + "(Type**) noexcept(f())", + "Using C-style cast. " + "Use reinterpret_cast(...) instead [readability/casting] [4]", + ) # Checks for false positives... self.TestLint("int a = int();", "") # constructor @@ -1107,6 +1110,7 @@ def testDeprecatedCast(self): self.TestLint("void Function(bool(FunctionPointerArg)()) {}", "") self.TestLint("typedef set SortedIdSet", "") self.TestLint("bool TraverseNode(T *Node, bool(VisitorBase:: *traverse) (T *t)) {}", "") + self.TestLint("void (*execute_)(operation_base*) noexcept(may_throw());", "") # The second parameter to a gMock method definition is a function signature # that often looks like a bad cast but should not picked up by lint.