Add more examples to clang tidy checkers
authorSylvestre Ledru <sylvestre@debian.org>
Tue, 11 Apr 2017 07:10:48 +0000 (07:10 +0000)
committerSylvestre Ledru <sylvestre@debian.org>
Tue, 11 Apr 2017 07:10:48 +0000 (07:10 +0000)
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D31860

llvm-svn: 299920

clang-tools-extra/docs/clang-tidy/checks/llvm-namespace-comment.rst
clang-tools-extra/docs/clang-tidy/checks/llvm-twine-local.rst
clang-tools-extra/docs/clang-tidy/checks/misc-inefficient-algorithm.rst
clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst
clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst
clang-tools-extra/docs/clang-tidy/checks/readability-redundant-string-init.rst
clang-tools-extra/docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst

index 881b202f9bfc78a38573decba4f58d661181a38b..f6bc598505d3e6edcfa6d4d64be0687dacb6a2d0 100644 (file)
@@ -12,6 +12,19 @@ http://llvm.org/docs/CodingStandards.html#namespace-indentation
 
 https://google.github.io/styleguide/cppguide.html#Namespaces
 
+.. code-block:: c++
+
+  namespace n1 {
+  void f();
+  }
+
+  // becomes
+
+  namespace n1 {
+  void f();
+  }  // namespace n1
+
+
 Options
 -------
 
index 5ce0302b5d8fe4b0ecbbdd46b652341cb69686f9..ec9ef1c60913cb8fcca83281dc83413dd3d9d014 100644 (file)
@@ -6,3 +6,11 @@ llvm-twine-local
 
 Looks for local ``Twine`` variables which are prone to use after frees and
 should be generally avoided.
+
+.. code-block:: c++
+
+  static Twine Moo = Twine("bark") + "bah";
+
+  // becomes
+
+  static std::string Moo = (Twine("bark") + "bah").str();
index c61db68e5a6175880d3553003de4c1bb16be297a..00324876c6faccc1d2274abdfaf4cd9bf7a0dc3e 100644 (file)
@@ -9,3 +9,21 @@ Warns on inefficient use of STL algorithms on associative containers.
 Associative containers implements some of the algorithms as methods which
 should be preferred to the algorithms in the algorithm header. The methods
 can take advanatage of the order of the elements.
+
+.. code-block:: c++
+
+  std::set<int> s;
+  auto it = std::find(s.begin(), s.end(), 43);
+
+  // becomes
+
+  auto it = s.find(43);
+
+.. code-block:: c++
+
+  std::set<int> s;
+  auto c = std::count(s.begin(), s.end(), 43);
+
+  // becomes
+
+  auto c = s.count(43);
index 4e037351b272e6ccd5c63e6498df96aa5cef16e2..de868b9185887c038a18d59856e9b3fcb7252fe0 100644 (file)
@@ -5,3 +5,22 @@ misc-unused-parameters
 
 Finds unused parameters and fixes them, so that `-Wunused-parameter` can be
 turned on.
+
+.. code-block:: c++
+
+  void a(int i) {}
+
+  // becomes
+
+  void a(int  /*i*/) {}
+
+
+.. code-block:: c++
+
+  static void staticFunctionA(int i);
+  static void staticFunctionA(int i) {}
+
+  // becomes
+
+  static void staticFunctionA()
+  static void staticFunctionA() {}
index fcd0375142547975742bd02af1d24f35bd0e8ddc..a27a48294ef981eed142c7b03d78341f4e528b62 100644 (file)
@@ -9,3 +9,13 @@ with implicit ``float`` to ``double`` promotions.
 For example, warns on ``::sin(0.f)``, because this funciton's parameter is a
 double. You probably meant to call ``std::sin(0.f)`` (in C++), or ``sinf(0.f)``
 (in C).
+
+.. code-block:: c++
+
+  float a;
+  asin(a);
+
+  // becomes
+
+  float a;
+  std::asin(a);
index a5530a9a8f336fba604bbf1fa3323575a34a0096..e4136ea42340669cb410da3bc9635c5b37ce9fa5 100644 (file)
@@ -12,3 +12,8 @@ Examples:
   // Initializing string with empty string literal is unnecessary.
   std::string a = "";
   std::string b("");
+
+  // becomes
+
+  std::string a;
+  std::string b;
index 83122356d4606bd6597e19bd6ef4f9702f20f641..54a70625a4e8470f1b250ff39967a468ed6b6a63 100644 (file)
@@ -5,3 +5,11 @@ readability-uniqueptr-delete-release
 
 Replace ``delete <unique_ptr>.release()`` with ``<unique_ptr> = nullptr``.
 The latter is shorter, simpler and does not require use of raw pointer APIs.
+
+.. code-block:: c++
+
+  delete P.release();
+
+  // becomes
+
+  P = nullptr;