diff options
Diffstat (limited to 'clang-tools-extra/docs')
4 files changed, 137 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 3ea1c51..e45f870 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -67,6 +67,14 @@ Code completion Code actions ^^^^^^^^^^^^ +- New ``Override pure virtual methods`` code action. When invoked on a class + definition, this action automatically generates C++ ``override`` declarations + for all pure virtual methods inherited from its base classes that have not yet + been implemented. The generated method stubs prompts the user for the actual + implementation. The overrides are intelligently grouped under their original + access specifiers (e.g., ``public``, ``protected``), creating new access + specifier blocks if necessary. + Signature help ^^^^^^^^^^^^^^ @@ -100,6 +108,12 @@ Improvements to clang-tidy New checks ^^^^^^^^^^ +- New :doc:`bugprone-invalid-enum-default-initialization + <clang-tidy/checks/bugprone/invalid-enum-default-initialization>` check. + + Detects default initialization (to 0) of variables with ``enum`` type where + the enum has no enumerator with value of 0. + - New :doc:`llvm-mlir-op-builder <clang-tidy/checks/llvm/use-new-mlir-op-builder>` check. @@ -128,6 +142,10 @@ Changes in existing checks - Improved :doc:`misc-header-include-cycle <clang-tidy/checks/misc/header-include-cycle>` check performance. +- Improved :doc:`modernize-use-designated-initializers + <clang-tidy/checks/modernize/use-designated-initializers>` check to + suggest using designated initializers for aliased aggregate types. + - Improved :doc:`modernize-use-std-format <clang-tidy/checks/modernize/use-std-format>` check to correctly match when the format string is converted to a different type by an implicit @@ -142,6 +160,10 @@ Changes in existing checks <clang-tidy/checks/portability/template-virtual-member-function>` check to avoid false positives on pure virtual member functions. +- Improved :doc:`readability-qualified-auto + <clang-tidy/checks/readability/qualified-auto>` check by adding the option + `IgnoreAliasing`, that allows not looking at underlying types of type aliases. + Removed checks ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst new file mode 100644 index 0000000..a3bd2b6 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/invalid-enum-default-initialization.rst @@ -0,0 +1,72 @@ +.. title:: clang-tidy - bugprone-invalid-enum-default-initialization + +bugprone-invalid-enum-default-initialization +============================================ + +Detects default initialization (to 0) of variables with ``enum`` type where +the enum has no enumerator with value of 0. + +In C++ a default initialization is performed if a variable is initialized with +initializer list or in other implicit ways, and no value is specified at the +initialization. In such cases the value 0 is used for the initialization. +This also applies to enumerations even if it does not have an enumerator with +value 0. In this way a variable with the ``enum`` type may contain initially an +invalid value (if the program expects that it contains only the listed +enumerator values). + +The check emits a warning only if an ``enum`` variable is default-initialized +(contrary to not initialized) and the ``enum`` does not have an enumerator with +value of 0. The type can be a scoped or non-scoped ``enum``. Unions are not +handled by the check (if it contains a member of enumeration type). + +.. code-block:: c++ + + enum class Enum1: int { + A = 1, + B + }; + + enum class Enum0: int { + A = 0, + B + }; + + void f() { + Enum1 X1{}; // warn: 'X1' is initialized to 0 + Enum1 X2 = Enum1(); // warn: 'X2' is initialized to 0 + Enum1 X3; // no warning: 'X3' is not initialized + Enum0 X4{}; // no warning: type has an enumerator with value of 0 + } + + struct S1 { + Enum1 A; + S(): A() {} // warn: 'A' is initialized to 0 + }; + + struct S2 { + int A; + Enum1 B; + }; + + S2 VarS2{}; // warn: member 'B' is initialized to 0 + +The check applies to initialization of arrays or structures with initialization +lists in C code too. In these cases elements not specified in the list (and have +enum type) are set to 0. + +.. code-block:: c + + enum Enum1 { + Enum1_A = 1, + Enum1_B + }; + struct Struct1 { + int a; + enum Enum1 b; + }; + + enum Enum1 Array1[2] = {Enum1_A}; // warn: omitted elements are initialized to 0 + enum Enum1 Array2[2][2] = {{Enum1_A}, {Enum1_A}}; // warn: last element of both nested arrays is initialized to 0 + enum Enum1 Array3[2][2] = {{Enum1_A, Enum1_A}}; // warn: elements of second array are initialized to 0 + + struct Struct1 S1 = {1}; // warn: element 'b' is initialized to 0 diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 20a43274f..b6444eb 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -106,6 +106,7 @@ Clang-Tidy Checks :doc:`bugprone-incorrect-roundings <bugprone/incorrect-roundings>`, :doc:`bugprone-infinite-loop <bugprone/infinite-loop>`, :doc:`bugprone-integer-division <bugprone/integer-division>`, + :doc:`bugprone-invalid-enum-default-initialization <bugprone/invalid-enum-default-initialization>`, :doc:`bugprone-lambda-function-name <bugprone/lambda-function-name>`, :doc:`bugprone-macro-parentheses <bugprone/macro-parentheses>`, "Yes" :doc:`bugprone-macro-repeated-side-effects <bugprone/macro-repeated-side-effects>`, diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/qualified-auto.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/qualified-auto.rst index efa0857..34390e2 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability/qualified-auto.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability/qualified-auto.rst @@ -96,3 +96,45 @@ Note in the LLVM alias, the default value is `false`. matched against only the type name (i.e. ``Type``). E.g. to suppress reports for ``std::array`` iterators use `std::array<.*>::(const_)?iterator` string. The default is an empty string. + +.. option:: IgnoreAliasing + + If set to `true` the check will use the underlying type to determine the type + that ``auto`` is deduced to. If set to `false` the check will not look beyond + the first type alias. + Default value is `true`. + + .. code-block:: c++ + + using IntPtr = int*; + IntPtr foo(); + + auto bar = foo(); + + If :option:`IgnoreAliasing` is set to `true`, it will be transformed into: + + .. code-block:: c++ + + auto *bar = foo(); + + Otherwise no changes will occur. + +Limitations +----------- + +When :option:`IgnoreAliasing` is set to `false`, there are cases where +Clang has not preserved the type alias and the underlying type will be used so +false positives may occur. + +For example: + +.. code-block:: c++ + + using IntPtr = int *; + + void loopPtr(const std::vector<IntPtr> &VectorIntPtr) { + + // May fail for IgnoreAliasing==false as AST does not have the 'IntPtr' + for (auto Data : VectorIntPtr) { + } + } |