[PATCH] D157242: [clang-tidy] Exclude delegate constructors in cppcoreguidelines-prefer-member-initializer

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 6 14:35:25 PDT 2023


PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp, ccotter.
Herald added subscribers: shchenz, kbarton, xazax.hun, nemanjai.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

As proposed by check fix would result in compilation error,
lets exclude delegate constructors from being checked.

Fixes: #52818


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157242

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
@@ -563,3 +563,10 @@
     // CHECK-FIXES: ASSIGN_IN_MACRO(n, 0)
   }
 };
+
+struct PR52818  {
+    PR52818() : bar(5) {}
+    PR52818(int) : PR52818() { bar = 3; }
+
+    int bar;
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   to ignore ``static`` variables declared within the scope of
   ``class``/``struct``.
 
+- Improved :doc:`cppcoreguidelines-prefer-member-initializer
+  <clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
+  exclude delegate constructors from being checked.
+
 - Improved :doc:`llvm-namespace-comment
   <clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -141,10 +141,11 @@
 }
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-      cxxConstructorDecl(hasBody(compoundStmt()), unless(isInstantiated()))
-          .bind("ctor"),
-      this);
+  Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
+                                        unless(isInstantiated()),
+                                        unless(isDelegatingConstructor()))
+                         .bind("ctor"),
+                     this);
 }
 
 void PreferMemberInitializerCheck::check(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157242.547607.patch
Type: text/x-patch
Size: 2128 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230806/f1f749cd/attachment-0001.bin>


More information about the cfe-commits mailing list