account.
.. option:: IgnoreSingleArgument
+
When true, the check will ignore the single argument.
.. option:: CommentBoolLiterals
Finds functions which may throw an exception directly or indirectly, but they
should not. The functions which should not throw exceptions are the following:
+
* Destructors
* Move constructors
* Move assignment operators
constructors. We suppress warnings if the copy and the move constructors are both
disabled (deleted or private), because there is nothing the perfect forwarding
constructor could hide in this case. We also suppress warnings for constructors
-like C3 that are guarded with an enable_if, assuming the programmer was aware of
+like C3 that are guarded with an ``enable_if``, assuming the programmer was aware of
the possible hiding.
Background
For deciding whether a constructor is guarded with enable_if, we consider the
default values of the type parameters and the types of the constructor
-parameters. If any part of these types is std::enable_if or std::enable_if_t, we
-assume the constructor is guarded.
+parameters. If any part of these types is ``std::enable_if`` or ``std::enable_if_t``,
+we assume the constructor is guarded.
Example:
.. code-block:: c++
-
+
void FancyFunction() {
[] { printf("Called from %s\n", __func__); }();
[] { printf("Now called from %s\n", __FUNCTION__); }();
Finds function calls where it is possible to cause a not null-terminated result.
Usually the proper length of a string is ``strlen(src) + 1`` or equal length of
-this expression, because the null terminator needs an extra space. Without the
+this expression, because the null terminator needs an extra space. Without the
null terminator it can result in undefined behaviour when the string is read.
The following and their respective ``wchar_t`` based functions are checked:
the passed third argument, which is ``size_t length``. That is why the length
of the allocated memory is not enough to hold the null terminator.
- .. code-block:: c
+.. code-block:: c
- static char *stringCpy(const std::string &str) {
- char *result = reinterpret_cast<char *>(malloc(str.size()));
- memcpy(result, str.data(), str.size());
- return result;
- }
+ static char *stringCpy(const std::string &str) {
+ char *result = reinterpret_cast<char *>(malloc(str.size()));
+ memcpy(result, str.data(), str.size());
+ return result;
+ }
In addition to issuing warnings, fix-it rewrites all the necessary code. It also
tries to adjust the capacity of the destination array:
- .. code-block:: c
+.. code-block:: c
- static char *stringCpy(const std::string &str) {
- char *result = reinterpret_cast<char *>(malloc(str.size() + 1));
- strcpy(result, str.data());
- return result;
- }
+ static char *stringCpy(const std::string &str) {
+ char *result = reinterpret_cast<char *>(malloc(str.size() + 1));
+ strcpy(result, str.data());
+ return result;
+ }
Note: It cannot guarantee to rewrite every of the path-sensitive memory
- allocations.
+allocations.
.. _MemcpyTransformation:
-------
.. option:: HeaderFileExtensions
- Default value: `";h;hh;hpp;hxx"`
+ Default value: ``";h;hh;hpp;hxx"``
A semicolon-separated list of filename extensions of header files (the
filename extensions should not contain a "." prefix). For extension-less
header files, use an empty string or leave an empty string between ";"
.. option:: ImplementationFileExtensions
- Default value: `"c;cc;cpp;cxx"`
+ Default value: ``"c;cc;cpp;cxx"``
Likewise, a semicolon-separated list of filename extensions of
implementation files.
.. option:: SizeThreshold
An unsigned integer specifying the minimum size of a string literal to be
- considered by the check. Default is `5U`.
+ considered by the check. Default is ``5U``.
.. option:: RatioThreshold
A string specifying the maximum threshold ratio [0, 1.0] of suspicious string
- literals to be considered. Default is `".2"`.
+ literals to be considered. Default is ``".2"``.
.. option:: MaxConcatenatedTokens
An unsigned integer specifying the maximum number of concatenated tokens.
- Default is `5U`.
+ Default is ``5U``.
bugprone-terminating-continue
=============================
-Detects `do while` loops with a condition always evaluating to false that
-have a `continue` statement, as this `continue` terminates the loop
+Detects ``do while`` loops with a condition always evaluating to false that
+have a ``continue`` statement, as this ``continue`` terminates the loop
effectively.
.. code-block:: c++
void f() {
do {
- // some code
+ // some code
continue; // terminating continue
// some other code
} while(false);
.. title:: clang-tidy - cert-con36-c
.. meta::
:http-equiv=refresh: 5;URL=bugprone-spuriously-wake-up-functions.html
-
+
cert-con36-c
============
The cert-con36-c check is an alias, please see
-`bugprone-spuriously-wake-up-functions <bugprone-spuriously-wake-up-functions.html>`_
+`bugprone-spuriously-wake-up-functions <bugprone-spuriously-wake-up-functions.html>`_
for more information.
.. title:: clang-tidy - cert-con54-cpp
.. meta::
:http-equiv=refresh: 5;URL=bugprone-spuriously-wake-up-functions.html
-
+
cert-con54-cpp
==============
The cert-con54-cpp check is an alias, please see
-`bugprone-spuriously-wake-up-functions <bugprone-spuriously-wake-up-functions.html>`_
+`bugprone-spuriously-wake-up-functions <bugprone-spuriously-wake-up-functions.html>`_
for more information.
cppcoreguidelines-avoid-non-const-global-variables
==================================================
-Finds non-const global variables as described in `I.2 of C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-global>` .
-As `R.6 of C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rr-global>` is a duplicate of rule I.2 it also covers that rule.
+Finds non-const global variables as described in `I.2 of C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-global>`_ .
+As `R.6 of C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rr-global>`_ is a duplicate of rule I.2 it also covers that rule.
.. code-block:: c++
The corresponding style guide rule:
https://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
+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:
Corresponding cpplint.py check name: `readability/casting`.
-This check is similar to `-Wold-style-cast`, but it suggests automated fixes
+This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
in some cases. The reported locations should not be different from the
-ones generated by `-Wold-style-cast`.
+ones generated by ``-Wold-style-cast``.
are often misleading to developers because the ``const`` applies to the pointer
rather than the pointee.
-For instance, in the following code, the resulting type is ``int *`` ``const``
+For instance, in the following code, the resulting type is ``int * const``
rather than ``const int *``:
.. code-block:: c++
and displays one example of a possible call graph loop (recursion).
References:
+
* CERT C++ Coding Standard rule `DCL56-CPP. Avoid cycles during initialization of static objects <https://wiki.sei.cmu.edu/confluence/display/cplusplus/DCL56-CPP.+Avoid+cycles+during+initialization+of+static+objects>`_.
* JPL Institutional Coding Standard for the C Programming Language (JPL DOCID D-60411) rule `2.4 Do not use direct or indirect recursion`.
* OpenCL Specification, Version 1.2 rule `6.9 Restrictions: i. Recursion is not supported. <https://www.khronos.org/registry/OpenCL/specs/opencl-1.2.pdf>`_.
Limitations:
+
* The check does not handle calls done through function pointers
* The check does not handle C++ destructors
either comment parameter name out or remove the parameter completely, if all
callers of the function are in the same translation unit and can be updated.
-The check is similar to the `-Wunused-parameter` compiler diagnostic and can be
+The check is similar to the ``-Wunused-parameter`` compiler diagnostic and can be
used to prepare a codebase to enabling of that diagnostic. By default the check
is more permissive (see :option:`StrictMode`).
-----------------
* Notice that the migration example above leaves the ``private`` access
- specification untouched. You might want to run the check:doc:`modernize-use-equals-delete
+ specification untouched. You might want to run the check :doc:`modernize-use-equals-delete
<modernize-use-equals-delete>` to get warnings for deleted functions in
private sections.
.. code-block:: c++
void foo() throw();
- void bar() throw(int) {}
+ void bar() throw(int) {}
transforms to:
.. code-block:: c++
void foo() noexcept;
- void bar() noexcept(false) {}
+ void bar() noexcept(false) {}
Options
-------
.. option:: ReplacementString
-Users can use :option:`ReplacementString` to specify a macro to use
-instead of ``noexcept``. This is useful when maintaining source code
-that uses custom exception specification marking other than
-``noexcept``. Fix-it hints will only be generated for non-throwing
-specifications.
+ Users can use :option:`ReplacementString` to specify a macro to use
+ instead of ``noexcept``. This is useful when maintaining source code
+ that uses custom exception specification marking other than
+ ``noexcept``. Fix-it hints will only be generated for non-throwing
+ specifications.
Example
^^^^^^^
.. code-block:: c++
- #define MACRO1 std::uncaught_exception
- #define MACRO2 std::uncaught_exception
-
- int uncaught_exception() {
- return 0;
- }
-
- int main() {
- int res;
-
- res = uncaught_exception();
- // No warning, since it is not the deprecated function from namespace std
-
- res = MACRO2();
- // Warning, but will not be replaced
-
- res = std::uncaught_exception();
- // Warning and replaced
-
- using std::uncaught_exception;
- // Warning and replaced
-
- res = uncaught_exception();
- // Warning and replaced
- }
+ #define MACRO1 std::uncaught_exception
+ #define MACRO2 std::uncaught_exception
+
+ int uncaught_exception() {
+ return 0;
+ }
+
+ int main() {
+ int res;
+
+ res = uncaught_exception();
+ // No warning, since it is not the deprecated function from namespace std
+
+ res = MACRO2();
+ // Warning, but will not be replaced
+
+ res = std::uncaught_exception();
+ // Warning and replaced
+
+ using std::uncaught_exception;
+ // Warning and replaced
+
+ res = uncaught_exception();
+ // Warning and replaced
+ }
After applying the fixes the code will look like the following:
.. code-block:: c++
- #define MACRO1 std::uncaught_exception
- #define MACRO2 std::uncaught_exception
-
- int uncaught_exception() {
- return 0;
- }
-
- int main() {
- int res;
-
- res = uncaught_exception();
-
- res = MACRO2();
-
- res = std::uncaught_exceptions();
-
- using std::uncaught_exceptions;
-
- res = uncaught_exceptions();
- }
+ #define MACRO1 std::uncaught_exception
+ #define MACRO2 std::uncaught_exception
+
+ int uncaught_exception() {
+ return 0;
+ }
+
+ int main() {
+ int res;
+
+ res = uncaught_exception();
+
+ res = MACRO2();
+
+ res = std::uncaught_exceptions();
+
+ using std::uncaught_exceptions;
+
+ res = uncaught_exceptions();
+ }
Examples:
.. code-block:: c++
-
+
const int foo();
const Clazz foo();
Clazz *const foo();
zircon-temporary-objects
========================
-Warns on construction of specific temporary objects in the Zircon kernel.
-If the object should be flagged, If the object should be flagged, the fully
+Warns on construction of specific temporary objects in the Zircon kernel.
+If the object should be flagged, If the object should be flagged, the fully
qualified type name must be explicitly passed to the check.
-For example, given the list of classes "Foo" and "NS::Bar", all of the
-following will trigger the warning:
+For example, given the list of classes "Foo" and "NS::Bar", all of the
+following will trigger the warning:
.. code-block:: c++
.. code-block:: c++
- Foo F; // Non-temporary construction okay
- Foo F(param); // Non-temporary construction okay
- Foo *F = new Foo(); // New construction okay
+ Foo F; // Non-temporary construction okay
+ Foo F(param); // Non-temporary construction okay
+ Foo *F = new Foo(); // New construction okay
- Bar(); // Not NS::Bar, so okay
- NS::Bar B; // Non-temporary construction okay
+ Bar(); // Not NS::Bar, so okay
+ NS::Bar B; // Non-temporary construction okay
-Note that objects must be explicitly specified in order to be flagged,
+Note that objects must be explicitly specified in order to be flagged,
and so objects that inherit a specified object will not be flagged.
This check matches temporary objects without regard for inheritance and so a
.. option:: Names
- A semi-colon-separated list of fully-qualified names of C++ classes that
+ A semi-colon-separated list of fully-qualified names of C++ classes that
should not be constructed as temporaries. Default is empty.