Bug 1551842 - Add new clang-tidy checkers from clang 8.0.0. r=sylvestre,froydnj
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Wed, 22 May 2019 14:55:45 +0000
changeset 474975 a234872a4356abb2002ce4d4a04467a983d3dc8e
parent 474974 1765feffe210b2348826f3e333eade8ce923dd6c
child 474976 edb5fc31b4f50d9fa842c2c09ad45341a17e99fd
push id36052
push userbtara@mozilla.com
push dateThu, 23 May 2019 04:37:46 +0000
treeherdermozilla-central@d12917561f27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssylvestre, froydnj
bugs1551842
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551842 - Add new clang-tidy checkers from clang 8.0.0. r=sylvestre,froydnj Differential Revision: https://phabricator.services.mozilla.com/D31229
tools/clang-tidy/config.yaml
tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp
tools/clang-tidy/test/bugprone-too-small-loop-variable.json
tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp
tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json
tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp
tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json
tools/clang-tidy/test/readability-const-return-type.cpp
tools/clang-tidy/test/readability-const-return-type.json
tools/clang-tidy/test/readability-isolate-declaration.cpp
tools/clang-tidy/test/readability-isolate-declaration.json
tools/clang-tidy/test/readability-magic-numbers.cpp
tools/clang-tidy/test/readability-magic-numbers.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -57,16 +57,18 @@ clang_checkers:
   - name: bugprone-suspicious-missing-comma
     reliability: high
   - name: bugprone-suspicious-semicolon
     reliability: high
   - name: bugprone-suspicious-string-compare
     reliability: high
   - name: bugprone-swapped-arguments
     reliability: high
+  - name: bugprone-too-small-loop-variable
+    reliability: high
   - name: bugprone-unused-raii
     reliability: high
   - name: bugprone-use-after-move
     reliability: high
   - name: clang-analyzer-core.CallAndMessage
     reliability: medium
   - name: clang-analyzer-core.DivideZero
     reliability: high
@@ -115,29 +117,33 @@ clang_checkers:
   - name: clang-analyzer-security.insecureAPI.vfork
     reliability: medium
   - name: clang-analyzer-unix.Malloc
     reliability: high
   - name: clang-analyzer-unix.cstring.BadSizeArg
     reliability: high
   - name: clang-analyzer-unix.cstring.NullArg
     reliability: high
+  - name: cppcoreguidelines-narrowing-conversions
+    reliability: high
   - name: misc-non-copyable-objects
     reliability: high
   - name: misc-redundant-expression
     reliability: medium
   - name: misc-unused-alias-decls
     reliability: high
   - name: misc-unused-using-decls
     reliability: high
   - name: modernize-avoid-bind
     restricted-platforms:
       - win32
       - win64
     reliability: medium
+  - name: modernize-deprecated-ios-base-aliases
+    reliability: high
   - name: modernize-loop-convert
     reliability: high
   - name: modernize-raw-string-literal
     reliability: high
   - name: modernize-redundant-void-arg
     reliability: high
     # We still have some old C code that is built with a C compiler, so this
     # might break the build.
@@ -186,16 +192,18 @@ clang_checkers:
   - name: performance-type-promotion-in-math-fn
     reliability: high
   - name: performance-unnecessary-copy-initialization
     reliability: high
   - name: performance-unnecessary-value-param
     reliability: high
   - name: readability-braces-around-statements
     reliability: high
+  - name: readability-const-return-type
+    reliability: high
   # Note: this can be loosened up by using the ShortStatementLines option
   - name: readability-container-size-empty
     reliability: high
   - name: readability-delete-null-pointer
     reliability: high
   - name: readability-else-after-return
     reliability: high
   - name: readability-implicit-bool-conversion
@@ -206,16 +214,22 @@ clang_checkers:
       - key: AllowIntegerConditions
         # The check will allow conditional integer conversions.
         value: 1
       - key: AllowPointerConditions
         # The check will allow conditional pointer conversions.
         value: 1
   - name: readability-inconsistent-declaration-parameter-name
     reliability: high
+  - name: readability-isolate-declaration
+    reliability: high
+  - name: readability-magic-numbers
+    # Bug 1553495 - we must see first its impact on our code.
+    publish: !!bool no
+    reliability: high
   - name: readability-misleading-indentation
     reliability: high
   - name: readability-non-const-parameter
     reliability: high
   - name: readability-redundant-control-flow
     reliability: high
   - name: readability-redundant-preprocessor
     reliability: high
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/bugprone-too-small-loop-variable.cpp
@@ -0,0 +1,4 @@
+int main() {
+  long size = 294967296l;
+  for (short i = 0; i < size; ++i) {}
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/bugprone-too-small-loop-variable.json
@@ -0,0 +1,1 @@
+[["warning", "loop variable has narrower type 'short' than iteration's upper bound 'long'", "bugprone-too-small-loop-variable"], {"reliability": "high"}]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.cpp
@@ -0,0 +1,4 @@
+class Foo {
+  int f;
+  void a_f(double val) { f = val;}
+};
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/cppcoreguidelines-narrowing-conversions.json
@@ -0,0 +1,1 @@
+[["warning", "narrowing conversion from 'double' to 'int'", "cppcoreguidelines-narrowing-conversions"], {"reliability": "high"}]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.cpp
@@ -0,0 +1,18 @@
+namespace std {
+class ios_base {
+public:
+  typedef int io_state;
+  typedef int open_mode;
+  typedef int seek_dir;
+
+  typedef int streampos;
+  typedef int streamoff;
+};
+
+template <class CharT>
+class basic_ios : public ios_base {
+};
+} // namespace std
+
+// Test function return values (declaration)
+std::ios_base::io_state f_5();
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/modernize-deprecated-ios-base-aliases.json
@@ -0,0 +1,1 @@
+[["warning", "'std::ios_base::io_state' is deprecated; use 'std::ios_base::iostate' instead", "modernize-deprecated-ios-base-aliases"], {"reliability": "high"}]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-const-return-type.cpp
@@ -0,0 +1,5 @@
+const int p1() {
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness
+// CHECK-FIXES: int p1() {
+  return 1;
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-const-return-type.json
@@ -0,0 +1,1 @@
+[["warning", "return type 'const int' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness", "readability-const-return-type"], {"reliability": "high"}]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-isolate-declaration.cpp
@@ -0,0 +1,7 @@
+void f() {
+  int * pointer = nullptr, value = 42, * const const_ptr = &value;
+  // This declaration will be diagnosed and transformed into:
+  // int * pointer = nullptr;
+  // int value = 42;
+  // int * const const_ptr = &value;
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-isolate-declaration.json
@@ -0,0 +1,1 @@
+[["warning", "multiple declarations in a single statement reduces readability", "readability-isolate-declaration"], {"reliability": "high"}]
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-magic-numbers.cpp
@@ -0,0 +1,4 @@
+void func() {
+  int radius = 2;
+  double circleArea = 3.1415926535 * radius * radius;
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-magic-numbers.json
@@ -0,0 +1,1 @@
+[["warning", "3.1415926535 is a magic number; consider replacing it with a named constant", "readability-magic-numbers"], {"reliability": "high"}]
\ No newline at end of file