[PATCH] D93333: tidy: supress warning for default member funcs

Chris Warner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 15 12:30:29 PST 2020


cwarner-8702 created this revision.
cwarner-8702 added reviewers: clang-tools-extra, alexfh_, malcolm.parsons.
cwarner-8702 added a project: clang-tools-extra.
Herald added subscribers: kbarton, nemanjai.
cwarner-8702 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Modify the cppcoreguidelines-pro-type-member-init checker to ignore warnings from the move and copy-constructors when they are compiler defined with `= default` outside of the type declaration.

Reported as LLVM bug 36819 <https://bugs.llvm.org/show_bug.cgi?id=36819>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93333

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
@@ -501,3 +501,19 @@
 void Bug33557() {
   NegativeImplicitInheritedCtor I(5);
 }
+
+struct NegativeDefaultedCtorOutOfDecl {
+  NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &);
+  int F;
+};
+
+NegativeDefaultedCtorOutOfDecl::NegativeDefaultedCtorOutOfDecl(const NegativeDefaultedCtorOutOfDecl &) = default;
+
+struct PositiveDefaultConstructorOutOfDecl {
+  PositiveDefaultConstructorOutOfDecl();
+  int F;
+  // CHECK-FIXES: int F{};
+};
+
+PositiveDefaultConstructorOutOfDecl::PositiveDefaultConstructorOutOfDecl() = default;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: constructor does not initialize these fields: F
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -297,6 +297,10 @@
     // Skip declarations delayed by late template parsing without a body.
     if (!Ctor->getBody())
       return;
+    // Skip out-of-band explicitly defaulted special member functions
+    // (except the default constructor).
+    if (Ctor->isExplicitlyDefaulted() && !Ctor->isDefaultConstructor())
+      return;
     checkMissingMemberInitializer(*Result.Context, *Ctor->getParent(), Ctor);
     checkMissingBaseClassInitializer(*Result.Context, *Ctor->getParent(), Ctor);
   } else if (const auto *Record =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93333.311993.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201215/7223156f/attachment-0001.bin>


More information about the cfe-commits mailing list