diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e80886b..03cb330 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,7 +2,7 @@ Changelog ********* -1.7 (Unreleased) +2.0 (Unreleased) ================== A bunch of long-overdue modernizations of the codebase! @@ -18,6 +18,7 @@ A bunch of long-overdue modernizations of the codebase! * build/include-what-you-use now supports a plethora of new functions, courtesy of @geoffviola (https://github.com/cpplint/cpplint/pull/94) * build/include-what-you-use will no longer err on similarly-named classes from other namespaces thanks to @geoffviola (https://github.com/cpplint/cpplint/pull/273) * Indented functions inside namespaces will now be correctly erred on, courtesy of @Yujinmon (https://github.com/cpplint/cpplint/pull/235) +* The check for C-style casts now looks for the standard fixed-width integer typenames instead of non-standard ones (e.g. int32_t instead of int32) thanks to @nate-thirdwave (https://github.com/cpplint/cpplint/pull/282) * `[[(un)likely]]` no longer clouds readability/braces's super spy−scanning of braces, courtesy of @aaronliu0130 (https://github.com/cpplint/cpplint/pull/265) * C++20 headers will no longer be flagged as C headers thanks to @miker2 (https://github.com/cpplint/cpplint/pull/216) * Same goes for C++23 and C23 headers, thanks to @aaronliu0130 (https://github.com/cpplint/cpplint/pull/239) diff --git a/cpplint.py b/cpplint.py index b39d4c4..a3f5649 100755 --- a/cpplint.py +++ b/cpplint.py @@ -3415,7 +3415,7 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum, if re.search(r'\b(const|volatile|void|char|short|int|long' r'|float|double|signed|unsigned' - r'|schar|u?int8|u?int16|u?int32|u?int64)' + r'|schar|u?int8_t|u?int16_t|u?int32_t|u?int64_t)' r'\s+(register|static|extern|typedef)\b', line): error(filename, linenum, 'build/storage_class', 5, @@ -5330,7 +5330,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, """Checks rules from the 'C++ language rules' section of cppguide.html. Some of these rules are hard to test (function overloading, using - uint32 inappropriately), but we do the best we can. + uint32_t inappropriately), but we do the best we can. Args: filename: The name of the current file. @@ -5383,7 +5383,7 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, match = re.search(r'\b(short|long(?! +double)|long long)\b', line) if match: error(filename, linenum, 'runtime/int', 4, - f'Use int16/int64/etc, rather than the C type {match.group(1)}') + f'Use int16_t/int64_t/etc, rather than the C type {match.group(1)}') # Check if some verboten operator overloading is going on # TODO(unknown): catch out-of-line unary operator&: @@ -5810,7 +5810,7 @@ def CheckCasts(filename, clean_lines, linenum, error): # probably a member operator declaration or default constructor. match = re.search( r'(\bnew\s+(?:const\s+)?|\S<\s*(?:const\s+)?)?\b' - r'(int|float|double|bool|char|int32|uint32|int64|uint64)' + r'(int|float|double|bool|char|int16_t|uint16_t|int32_t|uint32_t|int64_t|uint64_t)' r'(\([^)].*)', line) expecting_function = ExpectingFunctionArgs(clean_lines, linenum) if match and not expecting_function: @@ -5854,7 +5854,7 @@ def CheckCasts(filename, clean_lines, linenum, error): if not expecting_function: CheckCStyleCast(filename, clean_lines, linenum, 'static_cast', - r'\((int|float|double|bool|char|u?int(16|32|64)|size_t)\)', error) + r'\((int|float|double|bool|char|u?int(16|32|64)_t|size_t)\)', error) # This doesn't catch all cases. Consider (const char * const)"hello". # diff --git a/cpplint_unittest.py b/cpplint_unittest.py index d0303bd..94dd81c 100755 --- a/cpplint_unittest.py +++ b/cpplint_unittest.py @@ -461,36 +461,36 @@ def testLineLengthCheck(self): def testErrorSuppression(self): # Two errors on same line: self.TestLint( - 'long a = (int64) 65;', - ['Using C-style cast. Use static_cast(...) instead' + 'long a = (int64_t) 65;', + ['Using C-style cast. Use static_cast(...) instead' ' [readability/casting] [4]', - 'Use int16/int64/etc, rather than the C type long' + 'Use int16_t/int64_t/etc, rather than the C type long' ' [runtime/int] [4]', ]) # One category of error suppressed: self.TestLint( - 'long a = (int64) 65; // NOLINT(runtime/int)', - 'Using C-style cast. Use static_cast(...) instead' + 'long a = (int64_t) 65; // NOLINT(runtime/int)', + 'Using C-style cast. Use static_cast(...) instead' ' [readability/casting] [4]') # Two categories of errors suppressed: self.TestLint( - 'long a = (int64) 65; // NOLINT(runtime/int,readability/casting)', + 'long a = (int64_t) 65; // NOLINT(runtime/int,readability/casting)', '') # All categories suppressed: (two aliases) - self.TestLint('long a = (int64) 65; // NOLINT', '') - self.TestLint('long a = (int64) 65; // NOLINT(*)', '') + self.TestLint('long a = (int64_t) 65; // NOLINT', '') + self.TestLint('long a = (int64_t) 65; // NOLINT(*)', '') # Malformed NOLINT directive: self.TestLint( 'long a = 65; // NOLINT(foo)', ['Unknown NOLINT error category: foo' ' [readability/nolint] [5]', - 'Use int16/int64/etc, rather than the C type long [runtime/int] [4]', + 'Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]', ]) # Irrelevant NOLINT directive has no effect: self.TestLint( 'long a = 65; // NOLINT(readability/casting)', - 'Use int16/int64/etc, rather than the C type long' + 'Use int16_t/int64_t/etc, rather than the C type long' ' [runtime/int] [4]') # NOLINTNEXTLINE silences warning for the next line instead of current line error_collector = ErrorCollector(self.assertTrue) @@ -506,7 +506,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTNEXTLINE(runtime/int,readability/casting)', - 'long a = (int64) 65;', + 'long a = (int64_t) 65;', ''], error_collector) self.assertEqual('', error_collector.Results()) @@ -515,7 +515,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.h', 'h', ['// Copyright 2014 Your Company.', '// NOLINT(build/header_guard)', - 'int64 a = (uint64) 65;', + 'int64_t a = (uint64_t) 65;', '// LINT_C_FILE', ''], error_collector) @@ -549,7 +549,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.h', 'h', ['// Copyright 2014 Your Company.', '// NOLINT(build/header_guard)', - 'int64 a = (uint64) 65;', + 'int64_t a = (uint64_t) 65;', '/* Prevent warnings about the modeline', modeline, '*/', @@ -589,7 +589,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN', - 'long a = (int64) 65;' + 'long a = (int64_t) 65;' 'long a = 65;', '// ./command' + (' -verbose' * 80)], error_collector) @@ -598,7 +598,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN(*)', - 'long a = (int64) 65;' + 'long a = (int64_t) 65;' 'long a = 65;', '// ./command' + (' -verbose' * 80)], error_collector) @@ -608,7 +608,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN', - 'long a = (int64) 65;' + 'long a = (int64_t) 65;' 'long a = 65;', '// NOLINTEND', '// ./command' + (' -verbose' * 80), @@ -621,7 +621,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN(readability/casting,runtime/int)', - 'long a = (int64) 65;', + 'long a = (int64_t) 65;', 'long a = 65;', '// ./command' + (' -verbose' * 80), '// NOLINTEND', @@ -635,7 +635,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN(readability/casting,runtime/int)', - 'long a = (int64) 65;', + 'long a = (int64_t) 65;', 'long a = 65;', '// NOLINTEND(readability/casting)', ''], @@ -648,7 +648,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN(readability/casting,runtime/int)', - 'long a = (int64) 65;', + 'long a = (int64_t) 65;', '// NOLINTBEGIN(runtime/int)', 'long a = 65;', '// NOLINTEND(*)', @@ -661,7 +661,7 @@ def testErrorSuppression(self): cpplint.ProcessFileData('test.cc', 'cc', ['// Copyright 2014 Your Company.', '// NOLINTBEGIN(readability/casting,runtime/int)', - 'long a = (int64) 65;', + 'long a = (int64_t) 65;', 'long a = 65;', ''], error_collector) @@ -680,14 +680,14 @@ def testErrorSuppression(self): def testVariableDeclarations(self): self.TestLint( 'long a = 65;', - 'Use int16/int64/etc, rather than the C type long' + 'Use int16_t/int64_t/etc, rather than the C type long' ' [runtime/int] [4]') self.TestLint( 'long double b = 65.0;', '') self.TestLint( 'long long aa = 6565;', - 'Use int16/int64/etc, rather than the C type long' + 'Use int16_t/int64_t/etc, rather than the C type long' ' [runtime/int] [4]') # Test C-style cast cases. @@ -706,16 +706,16 @@ def testCStyleCast(self): ' [readability/casting] [4]') self.TestLint( - 'uint16 a = (uint16)1.0;', - 'Using C-style cast. Use static_cast(...) instead' + 'uint16_t a = (uint16_t)1.0;', + 'Using C-style cast. Use static_cast(...) instead' ' [readability/casting] [4]') self.TestLint( - 'int32 a = (int32)1.0;', - 'Using C-style cast. Use static_cast(...) instead' + 'int32_t a = (int32_t)1.0;', + 'Using C-style cast. Use static_cast(...) instead' ' [readability/casting] [4]') self.TestLint( - 'uint64 a = (uint64)1.0;', - 'Using C-style cast. Use static_cast(...) instead' + 'uint64_t a = (uint64_t)1.0;', + 'Using C-style cast. Use static_cast(...) instead' ' [readability/casting] [4]') self.TestLint( 'size_t a = (size_t)1.0;', @@ -861,7 +861,7 @@ def testCheckForUnnamedParams(self): self.TestLint('void Method(char* x) {', '') self.TestLint('void Method(char* /*x*/) {', '') self.TestLint('void Method(char* x);', '') - self.TestLint('typedef void (*Method)(int32 x);', '') + self.TestLint('typedef void (*Method)(int32_t x);', '') self.TestLint('static void operator delete[](void* x) throw();', '') self.TestLint('static void operator delete[](void* /*x*/) throw();', '') @@ -904,8 +904,8 @@ def testDeprecatedCast(self): self.TestLint('int a = int();', '') # constructor self.TestLint('X::X() : a(int()) {}', '') # default constructor self.TestLint('operator bool();', '') # Conversion operator - self.TestLint('new int64(123);', '') # "new" operator on basic type - self.TestLint('new int64(123);', '') # "new" operator on basic type + self.TestLint('new int64_t(123);', '') # "new" operator on basic type + self.TestLint('new int64_t(123);', '') # "new" operator on basic type self.TestLint('new const int(42);', '') # "new" on const-qualified type self.TestLint('using a = bool(int arg);', '') # C++11 alias-declaration self.TestLint('x = bit_cast(y);', '') # array of array @@ -940,7 +940,7 @@ def testDeprecatedCast(self): self.TestLint('typedef bool(MyClass::*MemberFunctionPointer)() const;', '') self.TestLint('void Function(bool(FunctionPointerArg)());', '') self.TestLint('void Function(bool(FunctionPointerArg)()) {}', '') - self.TestLint('typedef set SortedIdSet', '') + self.TestLint('typedef set SortedIdSet', '') self.TestLint( 'bool TraverseNode(T *Node, bool(VisitorBase:: *traverse) (T *t)) {}', '') @@ -5227,8 +5227,8 @@ def testBuildStorageClass(self): qualifiers = [None, 'const', 'volatile'] signs = [None, 'signed', 'unsigned'] types = ['void', 'char', 'int', 'float', 'double', - 'schar', 'int8', 'uint8', 'int16', 'uint16', - 'int32', 'uint32', 'int64', 'uint64'] + 'schar', 'int8_t', 'uint8_t', 'int16_t', 'uint16_t', + 'int32_t', 'uint32_t', 'int64_t', 'uint64_t'] storage_classes = ['extern', 'register', 'static', 'typedef'] build_storage_class_error_message = ( @@ -5245,7 +5245,7 @@ def testBuildStorageClass(self): self.TestLint('double const static foo = 2.0;', build_storage_class_error_message) - self.TestLint('uint64 typedef unsigned_long_long;', + self.TestLint('uint64_t typedef unsigned_long_long;', build_storage_class_error_message) self.TestLint('int register foo = 0;', @@ -6513,7 +6513,7 @@ def testArguments(self): self.assertEqual(len(self.nesting_state.stack), 0) def testInlineAssembly(self): - self.UpdateWithLines(['void CopyRow_SSE2(const uint8* src, uint8* dst,', + self.UpdateWithLines(['void CopyRow_SSE2(const uint8_t* src, uint8_t* dst,', ' int count) {']) self.assertEqual(len(self.nesting_state.stack), 1) self.assertEqual(self.nesting_state.stack[-1].open_parentheses, 0) diff --git a/samples/chromium-sample/simple.def b/samples/chromium-sample/simple.def index 925d3af..1e68efd 100644 --- a/samples/chromium-sample/simple.def +++ b/samples/chromium-sample/simple.def @@ -17,8 +17,8 @@ src/chrome_content_renderer_client.cc:1841: Add #include for string [ src/chrome_content_renderer_client.cc:5: samples/chromium-sample/src/chrome_content_renderer_client.cc should include its header file samples/chromium-sample/src/chrome_content_renderer_client.h [build/include] [5] src/chrome_content_renderer_client.h:5: #ifndef header guard has wrong style, please use: SAMPLES_CHROMIUM_SAMPLE_SRC_CHROME_CONTENT_RENDERER_CLIENT_H_ [build/header_guard] [5] src/chrome_content_renderer_client.h:225: #endif line should be "#endif // SAMPLES_CHROMIUM_SAMPLE_SRC_CHROME_CONTENT_RENDERER_CLIENT_H_" [build/header_guard] [5] -src/chrome_content_renderer_client.h:115: Use int16/int64/etc, rather than the C type long [runtime/int] [4] -src/chrome_content_renderer_client.h:117: Use int16/int64/etc, rather than the C type long [runtime/int] [4] +src/chrome_content_renderer_client.h:115: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4] +src/chrome_content_renderer_client.h:117: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4] src/io_thread.cc:242: Do not indent within a namespace. [whitespace/indent_namespace] [4] src/io_thread.cc:286: Do not indent within a namespace. [whitespace/indent_namespace] [4] src/io_thread.cc:298: Do not indent within a namespace. [whitespace/indent_namespace] [4] diff --git a/samples/codelite-sample/simple.def b/samples/codelite-sample/simple.def index 88c9bf0..012d3bc 100644 --- a/samples/codelite-sample/simple.def +++ b/samples/codelite-sample/simple.def @@ -478,7 +478,7 @@ src/pptable.cpp:512: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:513: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:514: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:515: Tab found; better to use spaces [whitespace/tab] [1] -src/pptable.cpp:515: Use int16/int64/etc, rather than the C type long [runtime/int] [4] +src/pptable.cpp:515: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4] src/pptable.cpp:516: Tab found; better to use spaces [whitespace/tab] [1] src/pptable.cpp:516: Lines should be <= 80 characters long [whitespace/line_length] [2] src/pptable.cpp:517: Tab found; better to use spaces [whitespace/tab] [1] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy