int&& x;
};
-The check implements
-`rule C.12 of C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c12-dont-make-data-members-const-or-references>`_.
+This check implements `C.12
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-constref>`_
+from the C++ Core Guidelines.
Further reading:
`Data members: Never const <https://quuxplusone.github.io/blog/2022/01/23/dont-const-all-the-things/#data-members-never-const>`_.
loops, since the termination condition is at the end and the condition is not
checked prior to the first iteration. This can lead to subtle bugs.
-The check implements
-`rule ES.75 of C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Res-do>`_.
+This check implements `ES.75
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-do>`_
+from the C++ Core Guidelines.
Examples:
The usage of ``goto`` for control flow is error prone and should be replaced
with looping constructs. Only forward jumps in nested loops are accepted.
-This check implements `ES.76 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es76-avoid-goto>`_
-from the CppCoreGuidelines and
-`6.3.1 from High Integrity C++ <http://www.codingstandard.com/rule/6-3-1-ensure-that-the-labels-for-a-jump-statement-or-a-switch-condition-appear-later-in-the-same-or-an-enclosing-block/>`_.
+This check implements `ES.76
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es76-avoid-goto>`_
+from the C++ Core Guidelines and
+`6.3.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard/statements>`_
+from High Integrity C++ Coding Standard.
For more information on why to avoid programming
with ``goto`` you can read the famous paper `A Case against the GO TO Statement. <https://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF>`_.
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
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i2-avoid-non-const-global-variables>`_
+of C++ Core Guidelines.
+As `R.6 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-global>`_
+of C++ Core Guidelines is a duplicate of rule `I.2
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i2-avoid-non-const-global-variables>`_
+it also covers that rule.
.. code-block:: c++
if (val) ...
}
-This check implements
-`CppCoreGuideline CP.53 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-reference-parameters>`_.
+This check implements `CP.53
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-reference-parameters>`_
+from the C++ Core Guidelines.
value. These may lead to unexpected behavior if there is a code path that reads
the variable before assigning to it.
+This rule is part of the `Type safety (Type.5)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-init>`_
+profile and `ES.20 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always>`_
+from the C++ Core Guidelines.
+
Only integers, booleans, floats, doubles and pointers are checked. The fix
option initializes all detected values with the value of zero. An exception is
float and double types, which are initialized to NaN.
This check flags initializers of globals that access extern objects,
and therefore can lead to order-of-initialization problems.
-This rule is part of the "Interfaces" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-global-init
+This check implements `I.22
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ri-global-init>`_
+from the C++ Core Guidelines.
Note that currently this does not flag calls to non-constexpr functions, and
therefore globals could still be accessed from functions themselves.
constructs exist for the task.
The relevant sections in the C++ Core Guidelines are
-`ES.31 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es31-dont-use-macros-for-constants-or-functions>`_, and
-`ES.32 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es32-use-all_caps-for-all-macro-names>`_.
+`ES.31 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es31-dont-use-macros-for-constants-or-functions>`_, and
+`ES.32 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es32-use-all_caps-for-all-macro-names>`_.
Examples:
}
};
-This check implements
-`CppCoreGuideline F.54 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f54-when-writing-a-lambda-that-captures-this-or-any-class-data-member-dont-use--default-capture>`_.
+This check implements `F.54
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f54-when-writing-a-lambda-that-captures-this-or-any-class-data-member-dont-use--default-capture>`_
+from the C++ Core Guidelines.
f(1, 2); // Incorrect - may not invoke the desired qualified function operator
}
-This check implements
-`CppCoreGuideline F.19 <http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-forward>`_.
+This check implements `F.19
+<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-forward>`_
+from the C++ Core Guidelines.
the issue is obvious in this former example, it might not be so in the
following: ``void MyClass::f(double d) { int_member_ += d; }``.
-This rule is part of the "Expressions and statements" profile of the C++ Core
-Guidelines, corresponding to rule ES.46. See
-
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es46-avoid-lossy-narrowing-truncating-arithmetic-conversions.
+This check implements `ES.46
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es46-avoid-lossy-narrowing-truncating-arithmetic-conversions>`_
+from the C++ Core Guidelines.
We enforce only part of the guideline, more specifically, we flag narrowing conversions from:
- an integer to a narrower integer (e.g. ``char`` to ``unsigned char``)
of an appropriate RAII object.
Furthermore, it can be configured to check against a user-specified list of functions
that are used for memory management (e.g. ``posix_memalign()``).
-See `C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rr-mallocfree>`_.
+
+This check implements `R.10
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-mallocfree>`_
+from the C++ Core Guidelines.
There is no attempt made to provide fix-it hints, since manual resource
management isn't easily transformed automatically into RAII.
=====================================
This check implements `C.37 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c37-make-destructors-noexcept>`_
-from the CppCoreGuidelines.
+from the C++ Core Guidelines.
The cppcoreguidelines-noexcept-destructor check is an alias, please see
`performance-noexcept-destructor <../performance/noexcept-destructor.html>`_
==========================================
This check implements `C.66 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c66-make-move-operations-noexcept>`_
-from the CppCoreGuidelines.
+from the C++ Core Guidelines.
The cppcoreguidelines-noexcept-move-operations check is an alias, please see
`performance-noexcept-move-constructor <../performance/noexcept-move-constructor.html>`_
This check implements `C.83 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c83-for-value-like-types-consider-providing-a-noexcept-swap-function>`_
, `C.84 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c84-a-swap-function-must-not-fail>`_
and `C.85 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c85-make-swap-noexcept>`_
-from the CppCoreGuidelines.
+from the C++ Core Guidelines.
The cppcoreguidelines-noexcept-swap check is an alias, please see
`performance-noexcept-swap <../performance/noexcept-swap.html>`_
static analysis on code, that uses raw pointers to handle resources like
dynamic memory, but won't introduce RAII concepts.
-The relevant sections in the `C++ Core Guidelines <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md>`_ are I.11, C.33, R.3 and GSL.Views
+This check implements `I.11
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#i11-never-transfer-ownership-by-a-raw-pointer-t-or-reference-t>`_,
+`C.33
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c33-if-a-class-has-an-owning-pointer-member-define-a-destructor>`_,
+`R.3
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r3-a-raw-pointer-a-t-is-non-owning>`_
+and `GSL.Views
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#SS-views>`_
+from the C++ Core Guidelines.
The definition of a ``gsl::owner<T*>`` is straight forward
.. code-block:: c++
namespace gsl { template <typename T> owner = T; }
It is therefore simple to introduce the owner even without using an implementation of
-the `Guideline Support Library <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gsl-guideline-support-library>`_.
+the `Guideline Support Library <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl>`_.
All checks are purely type based and not (yet) flow sensitive.
Class-member assignments inside a control statement or following the first
control statement are ignored.
-This check implements `C.49 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c49-prefer-initialization-to-assignment-in-constructors>`_ from the CppCoreGuidelines.
+This check implements `C.49
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c49-prefer-initialization-to-assignment-in-constructors>`_
+from the C++ Core Guidelines.
If the language version is `C++ 11` or above, the constructor is the default
constructor of the class, the field is not a bitfield (only in case of earlier
negated literal or ``enum`` constant then the preferred place of the
initialization is at the class member declaration.
-This latter rule is `C.48 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_ from CppCoreGuidelines.
+This latter rule is `C.48
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_
+from the C++ Core Guidelines.
Please note, that this check does not enforce this latter rule for
initializations already implemented as member initializers. For that purpose
Pointers should not be used as arrays. ``span<T>`` is a bounds-checked, safe
alternative to using pointers to access arrays.
-This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-decay.
+This rule is part of the `Bounds safety (Bounds 3)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-decay>`_
+profile from the C++ Core Guidelines.
are out of bounds (for ``std::array``). For out-of-bounds checking of static
arrays, see the `-Warray-bounds` Clang diagnostic.
-This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-arrayindex.
+This rule is part of the `Bounds safety (Bounds 2)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-arrayindex>`_
+profile from the C++ Core Guidelines.
Optionally, this check can generate fixes using ``gsl::at`` for indexing.
and easy to get wrong. ``span<T>`` is a bounds-checked, safe type for accessing
arrays of data.
-This rule is part of the "Bounds safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-arithmetic.
+This rule is part of the `Bounds safety (Bounds 1)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-arithmetic>`_
+profile from the C++ Core Guidelines.
Modifying a variable that was declared const is undefined behavior, even with
``const_cast``.
-This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-constcast.
+This rule is part of the `Type safety (Type 3)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-constcast>`_
+profile from the C++ Core Guidelines.
``reinterpret_cast`` followed by a ``const_cast``. This rule bans
``(T)expression`` only when used to perform an unsafe cast.
-This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-cstylecast.
+This rule is part of the `Type safety (Type.4)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-cstylecast>`_
+profile from the C++ Core Guidelines.
If set to `true`, the check will provide fix-its with literal initializers
\( ``int i = 0;`` \) instead of curly braces \( ``int i{};`` \).
-This rule is part of the "Type safety" profile of the C++ Core
-Guidelines, corresponding to rule Type.6. See
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-memberinit.
+This rule is part of the `Type safety (Type.6)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-memberinit>`_
+profile from the C++ Core Guidelines.
variable that is actually of type ``X`` to be accessed as if it were of an
unrelated type ``Z``.
-This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-reinterpretcast.
+This rule is part of the `Type safety (Type.1.1)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-reinterpretcast>`_
+profile from the C++ Core Guidelines.
variable that is actually of type ``X`` to be accessed as if it were of an
unrelated type ``Z``.
-This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-downcast.
+This rule is part of the `Type safety (Type.2)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-downcast>`_
+profile from the C++ Core Guidelines.
enforced to be safe in the language and so relies on programmer discipline to
get it right.
-This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-unions.
+This rule is part of the `Type safety (Type.7)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-unions>`_
+profile from the C++ Core Guidelines.
because it cannot generally be enforced to be safe in the language and so relies
on programmer discipline to get it right.
-This rule is part of the "Type safety" profile of the C++ Core Guidelines, see
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-type-varargs.
+This rule is part of the `Type safety (Type.8)
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-type-varargs>`_
+profile from the C++ Core Guidelines.
T other = std::forward<T>(t);
}
-This check implements
-`CppCoreGuideline F.18 <http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f18-for-will-move-from-parameters-pass-by-x-and-stdmove-the-parameter>`_.
+This check implements `F.18
+<http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f18-for-will-move-from-parameters-pass-by-x-and-stdmove-the-parameter>`_
+from the C++ Core Guidelines.
+
D d;
use(d); // Slice.
-See the relevant C++ Core Guidelines sections for details:
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es63-dont-slice
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c145-access-polymorphic-objects-through-pointers-and-references
+This check implements `ES.63
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es63-dont-slice>`_
+and `C.145
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c145-access-polymorphic-objects-through-pointers-and-references>`_
+from the C++ Core Guidelines.
Note that defining a function with ``= delete`` is considered to be a
definition.
-This rule is part of the "Constructors, assignments, and destructors" profile of the C++ Core
-Guidelines, corresponding to rule C.21. See
-
-https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all.
+This check implements `C.21
+<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-five>`_
+from the C++ Core Guidelines.
Options
-------
cppcoreguidelines-use-default-member-init
=========================================
-This check implements `C.48 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_ from the CppCoreGuidelines.
+This check implements `C.48 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-in-class-initializer>`_
+from the C++ Core Guidelines.
The cppcoreguidelines-use-default-member-init check is an alias, please see
`modernize-use-default-member-init <../modernize/use-default-member-init.html>`_
This check implements
`C.35 <http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual>`_
-from the CppCoreGuidelines.
+from the C++ Core Guidelines.
Note that this check will diagnose a class with a virtual method regardless of
whether the class is used as a base class or not.
This check implements detection of local variables which could be declared as
``const`` but are not. Declaring variables as ``const`` is required or recommended by many
coding guidelines, such as:
-`CppCoreGuidelines ES.25 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es25-declare-an-object-const-or-constexpr-unless-you-want-to-modify-its-value-later-on>`_
-and `AUTOSAR C++14 Rule A7-1-1 (6.7.1 Specifiers) <https://www.autosar.org/fileadmin/user_upload/standards/adaptive/17-03/AUTOSAR_RS_CPP14Guidelines.pdf>`_.
+`ES.25 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es25-declare-an-object-const-or-constexpr-unless-you-want-to-modify-its-value-later-on>`_
+from the C++ Core Guidelines and `AUTOSAR C++14 Rule A7-1-1 (6.7.1 Specifiers)
+<https://www.autosar.org/fileadmin/user_upload/standards/adaptive/17-03/AUTOSAR_RS_CPP14Guidelines.pdf>`_.
Please note that this check's analysis is type-based only. Variables that are not modified
but used to create a non-const handle that might escape the scope are not diagnosed