Bug 1466427 - Enable two new clang-tidy 6.0 checks. r=andi draft
authorJan Keromnes <janx@linux.com>
Fri, 03 Aug 2018 20:19:03 +0000
changeset 826427 e9e07e7778cf9a52a235aae30b726502298f0e02
parent 826426 8d1e91f0f7245c4dcc84fd94abd842946a6b8402
push id118329
push userjanx@linux.com
push dateFri, 03 Aug 2018 20:19:33 +0000
reviewersandi
bugs1466427
milestone63.0a1
Bug 1466427 - Enable two new clang-tidy 6.0 checks. r=andi MozReview-Commit-ID: 8bVdUxErGbr
tools/clang-tidy/config.yaml
tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp
tools/clang-tidy/test/performance-implicit-conversion-in-loop.json
tools/clang-tidy/test/readability-static-accessed-through-instance.cpp
tools/clang-tidy/test/readability-static-accessed-through-instance.json
--- a/tools/clang-tidy/config.yaml
+++ b/tools/clang-tidy/config.yaml
@@ -96,19 +96,18 @@ clang_checkers:
     # Too noisy because of the way how we implement NS_IMETHOD. See Bug 1420366.
     publish: !!bool no
   - name: mozilla-*
     publish: !!bool yes
   - name: performance-faster-string-find
     publish: !!bool yes
   - name: performance-for-range-copy
     publish: !!bool yes
-  # Only available from clang tidy 6.0. We are currently using 5.0
-  # - name: performance-implicit-conversion-in-loop
-  #   publish: !!bool yes
+  - name: performance-implicit-conversion-in-loop
+    publish: !!bool yes
   - name: performance-inefficient-string-concatenation
     publish: !!bool yes
   - name: performance-inefficient-vector-operation
     publish: !!bool yes
   - name: performance-type-promotion-in-math-fn
     publish: !!bool yes
   - name: performance-unnecessary-copy-initialization
     publish: !!bool yes
@@ -125,14 +124,13 @@ clang_checkers:
   - name: readability-redundant-smartptr-get
     publish: !!bool no
   - name: readability-redundant-string-cstr
     publish: !!bool yes
   - name: readability-redundant-string-init
     publish: !!bool yes
   - name: readability-uniqueptr-delete-release
     publish: !!bool yes
-# Only available from clang tidy 6.0. We are currently using 5.0
-# - name: readability-static-accessed-through-instance
-#   publish: !!bool yes
+  - name: readability-static-accessed-through-instance
+    publish: !!bool yes
 
 # Third party files from mozilla-central
 third_party: tools/rewriting/ThirdPartyPaths.txt
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.cpp
@@ -0,0 +1,50 @@
+// Iterator returning by value.
+template <typename T>
+struct Iterator {
+  void operator++();
+  T operator*();
+  bool operator!=(const Iterator& other);
+};
+
+// The template argument is an iterator type, and a view is an object you can
+// run a for loop on.
+template <typename T>
+struct View {
+  T begin();
+  T end();
+};
+
+// With this class, the implicit conversion is a call to the (implicit)
+// constructor of the class.
+template <typename T>
+class ImplicitWrapper {
+ public:
+  // Implicit!
+  ImplicitWrapper(const T& t);
+};
+
+template <typename T>
+class OperatorWrapper {
+ public:
+  OperatorWrapper() = delete;
+};
+
+struct SimpleClass {
+  int foo;
+  operator OperatorWrapper<SimpleClass>();
+};
+
+typedef View<Iterator<SimpleClass>> SimpleView;
+
+void ImplicitSimpleClassIterator() {
+  for (const ImplicitWrapper<SimpleClass>& foo : SimpleView()) {}
+  for (const ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
+  for (ImplicitWrapper<SimpleClass> foo : SimpleView()) {}
+}
+
+void ImplicitSimpleClassArray() {
+  SimpleClass array[5];
+  for (const ImplicitWrapper<SimpleClass>& foo : array) {}
+  for (const ImplicitWrapper<SimpleClass> foo : array) {}
+  for (ImplicitWrapper<SimpleClass> foo : array) {}
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/performance-implicit-conversion-in-loop.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"the type of the loop variable 'foo' is different from the one returned by the iterator and generates an implicit conversion; you can either change the type to the matching one ('const SimpleClass &' but 'const auto&' is always a valid option) or remove the reference to make it explicit that you are creating a new value\", \"performance-implicit-conversion-in-loop\"]]"
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.cpp
@@ -0,0 +1,19 @@
+struct C {
+  static void foo();
+  static int x;
+  int nsx;
+  void mf() {
+    (void)&x;    // OK, x is accessed inside the struct.
+    (void)&C::x; // OK, x is accessed using a qualified-id.
+    foo();       // OK, foo() is accessed inside the struct.
+  }
+  void ns() const;
+};
+
+int C::x = 0;
+
+// Expressions with side effects
+C &f(int, int, int, int);
+void g() {
+  f(1, 2, 3, 4).x;
+}
new file mode 100644
--- /dev/null
+++ b/tools/clang-tidy/test/readability-static-accessed-through-instance.json
@@ -0,0 +1,1 @@
+"[[\"warning\", \"static member accessed through instance\", \"readability-static-accessed-through-instance\"]]"
\ No newline at end of file