From: Sylvestre Ledru Date: Tue, 11 Apr 2017 07:10:48 +0000 (+0000) Subject: Add more examples to clang tidy checkers X-Git-Tag: llvmorg-5.0.0-rc1~8081 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09ffef2c107b88100655a548a8422afa9f9ff1ef;p=platform%2Fupstream%2Fllvm.git Add more examples to clang tidy checkers Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D31860 llvm-svn: 299920 --- diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm-namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm-namespace-comment.rst index 881b202f9bfc..f6bc598505d3 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm-namespace-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm-namespace-comment.rst @@ -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 ------- diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm-twine-local.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm-twine-local.rst index 5ce0302b5d8f..ec9ef1c60913 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm-twine-local.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm-twine-local.rst @@ -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(); diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-inefficient-algorithm.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-inefficient-algorithm.rst index c61db68e5a61..00324876c6fa 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/misc-inefficient-algorithm.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-inefficient-algorithm.rst @@ -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 s; + auto it = std::find(s.begin(), s.end(), 43); + + // becomes + + auto it = s.find(43); + +.. code-block:: c++ + + std::set s; + auto c = std::count(s.begin(), s.end(), 43); + + // becomes + + auto c = s.count(43); diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst index 4e037351b272..de868b918588 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/misc-unused-parameters.rst @@ -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() {} diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst b/clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst index fcd037514254..a27a48294ef9 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/performance-type-promotion-in-math-fn.rst @@ -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); diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability-redundant-string-init.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-redundant-string-init.rst index a5530a9a8f33..e4136ea42340 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability-redundant-string-init.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability-redundant-string-init.rst @@ -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; diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst index 83122356d460..54a70625a4e8 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst @@ -5,3 +5,11 @@ readability-uniqueptr-delete-release Replace ``delete .release()`` with `` = nullptr``. The latter is shorter, simpler and does not require use of raw pointer APIs. + +.. code-block:: c++ + + delete P.release(); + + // becomes + + P = nullptr;