diff options
Diffstat (limited to 'docs/clang-tidy/checks')
4 files changed, 60 insertions, 4 deletions
diff --git a/docs/clang-tidy/checks/google-objc-global-variable-declaration.rst b/docs/clang-tidy/checks/google-objc-global-variable-declaration.rst new file mode 100644 index 00000000..ae2b1ee3 --- /dev/null +++ b/docs/clang-tidy/checks/google-objc-global-variable-declaration.rst @@ -0,0 +1,42 @@ +.. title:: clang-tidy - google-objc-global-variable-declaration + +google-objc-global-variable-declaration +======================================= + +Finds global variable declarations in Objective-C files that are not follow the pattern +of variable names in Google's Objective-C Style Guide. + +The corresponding style guide rule: +http://google.github.io/styleguide/objcguide.html#variable-names + +All the global variables should follow the pattern of `g[A-Z].*` (variables) or +`k[A-Z].*` (constants). The check will suggest a variable name that follows the pattern +if it can be inferred from the original name. + +For code: + +.. code-block:: objc + static NSString* myString = @"hello"; + +The fix will be: + +.. code-block:: objc + static NSString* gMyString = @"hello"; + +Another example of constant: + +.. code-block:: objc + static NSString* const myConstString = @"hello"; + +The fix will be: + +.. code-block:: objc + static NSString* const kMyConstString = @"hello"; + +However for code that prefixed with non-alphabetical characters like: + +.. code-block:: objc + static NSString* __anotherString = @"world"; + +The check will give a warning message but will not be able to suggest a fix. The user +need to fix it on his own. diff --git a/docs/clang-tidy/checks/list.rst b/docs/clang-tidy/checks/list.rst index 38ff9cb7..1b74c007 100644 --- a/docs/clang-tidy/checks/list.rst +++ b/docs/clang-tidy/checks/list.rst @@ -60,6 +60,7 @@ Clang-Tidy Checks google-default-arguments google-explicit-constructor google-global-names-in-headers + google-objc-global-variable-declaration google-readability-braces-around-statements (redirects to readability-braces-around-statements) <google-readability-braces-around-statements> google-readability-casting google-readability-function-size (redirects to readability-function-size) <google-readability-function-size> diff --git a/docs/clang-tidy/checks/misc-redundant-expression.rst b/docs/clang-tidy/checks/misc-redundant-expression.rst index ddef9af9..83c29bd7 100644 --- a/docs/clang-tidy/checks/misc-redundant-expression.rst +++ b/docs/clang-tidy/checks/misc-redundant-expression.rst @@ -9,13 +9,13 @@ Depending on the operator expressions may be - redundant, -- always be ``true``, +- always ``true``, -- always be ``false``, +- always ``false``, -- always be a constant (zero or one). +- always a constant (zero or one). -Example: +Examples: .. code-block:: c++ diff --git a/docs/clang-tidy/checks/modernize-replace-random-shuffle.rst b/docs/clang-tidy/checks/modernize-replace-random-shuffle.rst index 353f35a8..50674d42 100644 --- a/docs/clang-tidy/checks/modernize-replace-random-shuffle.rst +++ b/docs/clang-tidy/checks/modernize-replace-random-shuffle.rst @@ -26,3 +26,16 @@ Both of these examples will be replaced with: The second example will also receive a warning that ``randomFunc`` is no longer supported in the same way as before so if the user wants the same functionality, the user will need to change the implementation of the ``randomFunc``. One thing to be aware of here is that ``std::random_device`` is quite expensive to initialize. So if you are using the code in a performance critical place, you probably want to initialize it elsewhere. +Another thing is that the seeding quality of the suggested fix is quite poor: ``std::mt19937`` has an internal state of 624 32-bit integers, but is only seeded with a single integer. So if you require +higher quality randomness, you should consider seeding better, for example: + +.. code-block:: c++ + + std::shuffle(v.begin(), v.end(), []() { + std::mt19937::result_type seeds[std::mt19937::state_size]; + std::random_device device; + std::uniform_int_distribution<typename std::mt19937::result_type> dist; + std::generate(std::begin(seeds), std::end(seeds), [&] { return dist(device); }); + std::seed_seq seq(std::begin(seeds), std::end(seeds)); + return std::mt19937(seq); + }()); |