diff options
Diffstat (limited to 'clang-tools-extra/docs')
4 files changed, 244 insertions, 1 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 8a0151f..915b793 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -221,6 +221,11 @@ New checks Detect redundant parentheses. +- New :doc:`readability-redundant-typename + <clang-tidy/checks/readability/redundant-typename>` check. + + Finds redundant uses of the ``typename`` keyword. + New check aliases ^^^^^^^^^^^^^^^^^ @@ -320,6 +325,12 @@ Changes in existing checks <clang-tidy/checks/cppcoreguidelines/init-variables>` check by fixing the insertion location for function pointers with multiple parameters. +- Improved :doc:`cppcoreguidelines-macro-usage + <clang-tidy/checks/cppcoreguidelines/macro-usage>` check by excluding macro + bodies that starts with ``__attribute__((..))`` keyword. + Such a macro body is unlikely a proper expression and so suggesting users + an impossible rewrite into a template function should be avoided. + - Improved :doc:`cppcoreguidelines-prefer-member-initializer <clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to avoid false positives on inherited members in class templates. @@ -375,6 +386,11 @@ Changes in existing checks on Windows when the check was enabled with a 32-bit :program:`clang-tidy` binary. +- Improved :doc:`modernize-use-scoped-lock + <clang-tidy/checks/modernize/use-scoped-lock>` check by fixing a crash + on malformed code (common when using :program:`clang-tidy` through + :program:`clangd`). + - 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 @@ -411,7 +427,8 @@ Changes in existing checks - Improved :doc:`readability-identifier-naming <clang-tidy/checks/readability/identifier-naming>` check by ignoring declarations and macros in system headers. The documentation is also improved - to differentiate the general options from the specific ones. + to differentiate the general options from the specific ones. Options for + fine-grained control over ``constexpr`` variables were added. - Improved :doc:`readability-implicit-bool-conversion <clang-tidy/checks/readability/implicit-bool-conversion>` check by correctly diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index a324d18..d3c89e4 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -410,6 +410,7 @@ Clang-Tidy Checks :doc:`readability-redundant-smartptr-get <readability/redundant-smartptr-get>`, "Yes" :doc:`readability-redundant-string-cstr <readability/redundant-string-cstr>`, "Yes" :doc:`readability-redundant-string-init <readability/redundant-string-init>`, "Yes" + :doc:`readability-redundant-typename <readability/redundant-typename>`, "Yes" :doc:`readability-reference-to-constructed-temporary <readability/reference-to-constructed-temporary>`, :doc:`readability-simplify-boolean-expr <readability/simplify-boolean-expr>`, "Yes" :doc:`readability-simplify-subscript-expr <readability/simplify-subscript-expr>`, "Yes" diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst index 0e031a1..6c4e0b7 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst @@ -59,6 +59,7 @@ The available options are summarized below: - :option:`AbstractClassCase`, :option:`AbstractClassPrefix`, :option:`AbstractClassSuffix`, :option:`AbstractClassIgnoredRegexp`, :option:`AbstractClassHungarianPrefix` - :option:`ClassCase`, :option:`ClassPrefix`, :option:`ClassSuffix`, :option:`ClassIgnoredRegexp`, :option:`ClassHungarianPrefix` + - :option:`ClassConstexprCase`, :option:`ClassConstexprPrefix`, :option:`ClassConstexprSuffix`, :option:`ClassConstexprIgnoredRegexp`, :option:`ClassConstexprHungarianPrefix` - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, :option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`, :option:`ClassConstantHungarianPrefix` - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, :option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`, :option:`ClassMemberHungarianPrefix` - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, :option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp` @@ -73,12 +74,14 @@ The available options are summarized below: - :option:`EnumCase`, :option:`EnumPrefix`, :option:`EnumSuffix`, :option:`EnumIgnoredRegexp` - :option:`EnumConstantCase`, :option:`EnumConstantPrefix`, :option:`EnumConstantSuffix`, :option:`EnumConstantIgnoredRegexp`, :option:`EnumConstantHungarianPrefix` - :option:`FunctionCase`, :option:`FunctionPrefix`, :option:`FunctionSuffix`, :option:`FunctionIgnoredRegexp` + - :option:`GlobalConstexprVariableCase`, :option:`GlobalConstexprVariablePrefix`, :option:`GlobalConstexprVariableSuffix`, :option:`GlobalConstexprVariableIgnoredRegexp`, :option:`GlobalConstexprVariableHungarianPrefix` - :option:`GlobalConstantCase`, :option:`GlobalConstantPrefix`, :option:`GlobalConstantSuffix`, :option:`GlobalConstantIgnoredRegexp`, :option:`GlobalConstantHungarianPrefix` - :option:`GlobalConstantPointerCase`, :option:`GlobalConstantPointerPrefix`, :option:`GlobalConstantPointerSuffix`, :option:`GlobalConstantPointerIgnoredRegexp`, :option:`GlobalConstantPointerHungarianPrefix` - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`, :option:`GlobalFunctionIgnoredRegexp` - :option:`GlobalPointerCase`, :option:`GlobalPointerPrefix`, :option:`GlobalPointerSuffix`, :option:`GlobalPointerIgnoredRegexp`, :option:`GlobalPointerHungarianPrefix` - :option:`GlobalVariableCase`, :option:`GlobalVariablePrefix`, :option:`GlobalVariableSuffix`, :option:`GlobalVariableIgnoredRegexp`, :option:`GlobalVariableHungarianPrefix` - :option:`InlineNamespaceCase`, :option:`InlineNamespacePrefix`, :option:`InlineNamespaceSuffix`, :option:`InlineNamespaceIgnoredRegexp` + - :option:`LocalConstexprVariableCase`, :option:`LocalConstexprVariablePrefix`, :option:`LocalConstexprVariableSuffix`, :option:`LocalConstexprVariableIgnoredRegexp`, :option:`LocalConstexprVariableHungarianPrefix` - :option:`LocalConstantCase`, :option:`LocalConstantPrefix`, :option:`LocalConstantSuffix`, :option:`LocalConstantIgnoredRegexp`, :option:`LocalConstantHungarianPrefix` - :option:`LocalConstantPointerCase`, :option:`LocalConstantPointerPrefix`, :option:`LocalConstantPointerSuffix`, :option:`LocalConstantPointerIgnoredRegexp`, :option:`LocalConstantPointerHungarianPrefix` - :option:`LocalPointerCase`, :option:`LocalPointerPrefix`, :option:`LocalPointerSuffix`, :option:`LocalPointerIgnoredRegexp`, :option:`LocalPointerHungarianPrefix` @@ -97,6 +100,7 @@ The available options are summarized below: - :option:`PublicMemberCase`, :option:`PublicMemberPrefix`, :option:`PublicMemberSuffix`, :option:`PublicMemberIgnoredRegexp`, :option:`PublicMemberHungarianPrefix` - :option:`PublicMethodCase`, :option:`PublicMethodPrefix`, :option:`PublicMethodSuffix`, :option:`PublicMethodIgnoredRegexp` - :option:`ScopedEnumConstantCase`, :option:`ScopedEnumConstantPrefix`, :option:`ScopedEnumConstantSuffix`, :option:`ScopedEnumConstantIgnoredRegexp` + - :option:`StaticConstexprVariableCase`, :option:`StaticConstexprVariablePrefix`, :option:`StaticConstexprVariableSuffix`, :option:`StaticConstexprVariableIgnoredRegexp`, :option:`StaticConstexprVariableHungarianPrefix` - :option:`StaticConstantCase`, :option:`StaticConstantPrefix`, :option:`StaticConstantSuffix`, :option:`StaticConstantIgnoredRegexp`, :option:`StaticConstantHungarianPrefix` - :option:`StaticVariableCase`, :option:`StaticVariablePrefix`, :option:`StaticVariableSuffix`, :option:`StaticVariableIgnoredRegexp`, :option:`StaticVariableHungarianPrefix` - :option:`StructCase`, :option:`StructPrefix`, :option:`StructSuffix`, :option:`StructIgnoredRegexp` @@ -307,6 +311,58 @@ After: ~pre_foo_post(); }; +.. option:: ClassConstexprCase + + When defined, the check will ensure class ``constexpr`` names conform to + the selected casing. + +.. option:: ClassConstexprPrefix + + When defined, the check will ensure class ``constexpr`` names will add the + prefixed with the given value (regardless of casing). + +.. option:: ClassConstexprIgnoredRegexp + + Identifier naming checks won't be enforced for class ``constexpr`` names + matching this regular expression. + +.. option:: ClassConstexprSuffix + + When defined, the check will ensure class ``constexpr`` names will add the + suffix with the given value (regardless of casing). + +.. option:: ClassConstexprHungarianPrefix + + When enabled, the check ensures that the declared identifier will have a + Hungarian notation prefix based on the declared type. + +For example using values of: + + - ClassConstexprCase of ``lower_case`` + - ClassConstexprPrefix of ``pre_`` + - ClassConstexprSuffix of ``_post`` + - ClassConstexprHungarianPrefix of ``On`` + +Identifies and/or transforms class ``constexpr`` variable names as follows: + +Before: + +.. code-block:: c++ + + class FOO { + public: + static constexpr int CLASS_CONSTEXPR; + }; + +After: + +.. code-block:: c++ + + class FOO { + public: + static const int pre_class_constexpr_post; + }; + .. option:: ClassConstantCase When defined, the check will ensure class constant names conform to the @@ -950,6 +1006,52 @@ After: different style. Default value is `true`. +.. option:: GlobalConstexprVariableCase + + When defined, the check will ensure global ``constexpr`` variable names + conform to the selected casing. + +.. option:: GlobalConstexprVariablePrefix + + When defined, the check will ensure global ``constexpr`` variable names + will add the prefixed with the given value (regardless of casing). + +.. option:: GlobalConstexprVariableIgnoredRegexp + + Identifier naming checks won't be enforced for global ``constexpr`` + variable names matching this regular expression. + +.. option:: GlobalConstexprVariableSuffix + + When defined, the check will ensure global ``constexpr`` variable names + will add the suffix with the given value (regardless of casing). + +.. option:: GlobalConstexprVariableHungarianPrefix + + When enabled, the check ensures that the declared identifier will have a + Hungarian notation prefix based on the declared type. + +For example using values of: + + - GlobalConstexprVariableCase of ``lower_case`` + - GlobalConstexprVariablePrefix of ``pre_`` + - GlobalConstexprVariableSuffix of ``_post`` + - GlobalConstexprVariableHungarianPrefix of ``On`` + +Identifies and/or transforms global ``constexpr`` variable names as follows: + +Before: + +.. code-block:: c++ + + constexpr unsigned ImportantValue = 69; + +After: + +.. code-block:: c++ + + constexpr unsigned pre_important_value_post = 69; + .. option:: GlobalConstantCase When defined, the check will ensure global constant names conform to the @@ -1228,6 +1330,52 @@ After: } } // namespace FOO_NS +.. option:: LocalConstexprVariableCase + + When defined, the check will ensure local ``constexpr`` variable names + conform to the selected casing. + +.. option:: LocalConstexprVariablePrefix + + When defined, the check will ensure local ``constexpr`` variable names will + add the prefixed with the given value (regardless of casing). + +.. option:: LocalConstexprVariableIgnoredRegexp + + Identifier naming checks won't be enforced for local ``constexpr`` variable + names matching this regular expression. + +.. option:: LocalConstexprVariableSuffix + + When defined, the check will ensure local ``constexpr`` variable names will + add the suffix with the given value (regardless of casing). + +.. option:: LocalConstexprVariableHungarianPrefix + + When enabled, the check ensures that the declared identifier will have a + Hungarian notation prefix based on the declared type. + +For example using values of: + + - LocalConstexprVariableCase of ``lower_case`` + - LocalConstexprVariablePrefix of ``pre_`` + - LocalConstexprVariableSuffix of ``_post`` + - LocalConstexprVariableHungarianPrefix of ``On`` + +Identifies and/or transforms local ``constexpr`` variable names as follows: + +Before: + +.. code-block:: c++ + + void foo() { int const local_Constexpr = 420; } + +After: + +.. code-block:: c++ + + void foo() { int const pre_local_constexpr_post = 420; } + .. option:: LocalConstantCase When defined, the check will ensure local constant names conform to the @@ -2077,6 +2225,52 @@ After: enum class FOO { pre_One_post, pre_Two_post, pre_Three_post }; +.. option:: StaticConstexprVariableCase + + When defined, the check will ensure static ``constexpr`` variable names + conform to the selected casing. + +.. option:: StaticConstexprVariablePrefix + + When defined, the check will ensure static ``constexpr`` variable names + will add the prefixed with the given value (regardless of casing). + +.. option:: StaticConstexprVariableIgnoredRegexp + + Identifier naming checks won't be enforced for static ``constexpr`` + variable names matching this regular expression. + +.. option:: StaticConstexprVariableSuffix + + When defined, the check will ensure static ``constexpr`` variable names + will add the suffix with the given value (regardless of casing). + +.. option:: StaticConstexprVariableHungarianPrefix + + When enabled, the check ensures that the declared identifier will have a + Hungarian notation prefix based on the declared type. + +For example using values of: + + - StaticConstexprVariableCase of ``lower_case`` + - StaticConstexprVariablePrefix of ``pre_`` + - StaticConstexprVariableSuffix of ``_post`` + - StaticConstexprVariableHungarianPrefix of ``On`` + +Identifies and/or transforms static ``constexpr`` variable names as follows: + +Before: + +.. code-block:: c++ + + static unsigned constexpr MyConstexprStatic_array[] = {1, 2, 3}; + +After: + +.. code-block:: c++ + + static unsigned constexpr pre_my_constexpr_static_array_post[] = {1, 2, 3}; + .. option:: StaticConstantCase When defined, the check will ensure static constant names conform to the diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.rst b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.rst new file mode 100644 index 0000000..3f3e5de --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-typename.rst @@ -0,0 +1,31 @@ +.. title:: clang-tidy - readability-redundant-typename + +readability-redundant-typename +============================== + +Finds redundant uses of the ``typename`` keyword. + +``typename`` is redundant in two cases. First, before non-dependent names: + +.. code-block:: c++ + + /*typename*/ std::vector<int>::size_type size; + +And second, since C++20, before dependent names that appear in a context +where only a type is allowed (the following example shows just a few of them): + +.. code-block:: c++ + + template <typename T> + using trait = /*typename*/ T::type; + + template <typename T> + /*typename*/ T::underlying_type as_underlying(T n) { + return static_cast</*typename*/ T::underlying_type>(n); + } + + template <typename T> + struct S { + /*typename*/ T::type variable; + /*typename*/ T::type function(/*typename*/ T::type); + }; |
