[clang-tools-extra] b507bda - [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

Carlos Galvez via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 16 23:39:59 PDT 2023


Author: Carlos Galvez
Date: 2023-04-17T06:09:59Z
New Revision: b507bda4552347e00197032526c7ab4a80a853c2

URL: https://github.com/llvm/llvm-project/commit/b507bda4552347e00197032526c7ab4a80a853c2
DIFF: https://github.com/llvm/llvm-project/commit/b507bda4552347e00197032526c7ab4a80a853c2.diff

LOG: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

And deprecate identical functionality from
cppcoreguidelines-prefer-member-initializer, which had too many
responsibilities and a tight coupling to the
modernize-use-default-member-init check.

Fixes https://github.com/llvm/llvm-project/issues/62164.

Differential Revision: https://reviews.llvm.org/D148460

Added: 
    clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst

Modified: 
    clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
    clang-tools-extra/docs/ReleaseNotes.rst
    clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
    clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index ebffc97127cb6..c0f6a07b57eb5 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../readability/MagicNumbersCheck.h"
 #include "AvoidCapturingLambdaCoroutinesCheck.h"
@@ -110,6 +111,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
     CheckFactories.registerCheck<SpecialMemberFunctionsCheck>(
         "cppcoreguidelines-special-member-functions");
     CheckFactories.registerCheck<SlicingCheck>("cppcoreguidelines-slicing");
+    CheckFactories.registerCheck<modernize::UseDefaultMemberInitCheck>(
+        "cppcoreguidelines-use-default-member-init");
     CheckFactories.registerCheck<misc::UnconventionalAssignOperatorCheck>(
         "cppcoreguidelines-c-copy-assignment-signature");
     CheckFactories.registerCheck<VirtualClassDestructorCheck>(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 61cd67c1745f9..55c3416235952 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@ New check aliases
   <clang-tidy/checks/cert/msc33-c>` to :doc:`bugprone-unsafe-functions
   <clang-tidy/checks/bugprone/unsafe-functions>` was added.
 
+- New alias :doc:`cppcoreguidelines-use-default-member-init
+  <clang-tidy/checks/cppcoreguidelines/use-default-member-init>` to
+  :doc:`modernize-use-default-member-init
+  <clang-tidy/checks/modernize/use-default-member-init>` was added.
+
 Changes in existing checks
 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Improved :doc:`readability-redundant-string-cstr
@@ -215,6 +220,11 @@ Changes in existing checks
 - Deprecated :doc:`cert-dcl21-cpp
   <clang-tidy/checks/cert/dcl21-cpp>` check.
 
+- Deprecated C.48 enforcement from :doc:`cppcoreguidelines-prefer-member-initializer
+  <clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>`. Please use
+  :doc:`cppcoreguidelines-use-default-member-init
+  <clang-tidy/checks/cppcoreguidelines/use-default-member-init>` instead.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   <clang-tidy/checks/google/build-namespaces>` check.

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
index dea9450b86fd3..803cdbd64edb8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -23,6 +23,13 @@ Please note, that this check does not enforce this latter rule for
 initializations already implemented as member initializers. For that purpose
 see check `modernize-use-default-member-init <../modernize/use-default-member-init.html>`_.
 
+.. note::
+
+  Enforcement of rule C.48 in this check is deprecated, to be removed in
+  :program:`clang-tidy` version 19 (only C.49 will be enforced by this check then).
+  Please use `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+  to enfoce rule C.48.
+
 Example 1
 ---------
 
@@ -85,6 +92,11 @@ Here ``n`` can be initialized in the constructor initialization list, unlike
 
 .. option:: UseAssignment
 
+   Note: this option is deprecated, to be removed in :program:`clang-tidy`
+   version 19. Please use the `UseAssignment` option from
+   `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+   instead.
+
    If this option is set to `true` (by default `UseAssignment` from
    `modernize-use-default-member-init
    <../modernize/use-default-member-init.html>`_ will be used),

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
new file mode 100644
index 0000000000000..7f435e5292d03
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-use-default-member-init
+.. meta::
+   :http-equiv=refresh: 5;URL=../modernize/use-default-member-init.html
+
+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.
+
+The cppcoreguidelines-use-default-member-init check is an alias, please see
+`modernize-use-default-member-init <../modernize/use-default-member-init.html>`_
+for more information.

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 38727f69ea564..be0d32e65a7f6 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -477,6 +477,7 @@ Clang-Tidy Checks
    `cppcoreguidelines-explicit-virtual-functions <cppcoreguidelines/explicit-virtual-functions.html>`_, `modernize-use-override <modernize/use-override.html>`_, "Yes"
    `cppcoreguidelines-macro-to-enum <cppcoreguidelines/macro-to-enum.html>`_, `modernize-macro-to-enum <modernize/macro-to-enum.html>`_, "Yes"
    `cppcoreguidelines-non-private-member-variables-in-classes <cppcoreguidelines/non-private-member-variables-in-classes.html>`_, `misc-non-private-member-variables-in-classes <misc/non-private-member-variables-in-classes.html>`_,
+   `cppcoreguidelines-use-default-member-init <cppcoreguidelines/use-default-member-init.html>`_, `modernize-use-default-member-init <modernize/use-default-member-init.html>`_,
    `fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces.html>`_, `google-build-namespaces <google/build-namespaces.html>`_,
    `google-readability-braces-around-statements <google/readability-braces-around-statements.html>`_, `readability-braces-around-statements <readability/braces-around-statements.html>`_, "Yes"
    `google-readability-function-size <google/readability-function-size.html>`_, `readability-function-size <readability/function-size.html>`_,


        


More information about the cfe-commits mailing list