[PATCH] D57665: [clang-tidy] Handle unions with existing default-member-init

Malcolm Parsons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 4 13:09:37 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE353092: [clang-tidy] Handle unions with existing default-member-init (authored by malcolm.parsons, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D57665?vs=184976&id=185141#toc

Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57665/new/

https://reviews.llvm.org/D57665

Files:
  clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
  test/clang-tidy/modernize-use-default-member-init.cpp


Index: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===================================================================
--- clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -273,7 +273,7 @@
 
 void UseDefaultMemberInitCheck::checkExistingInit(
     const MatchFinder::MatchResult &Result, const CXXCtorInitializer *Init) {
-  const FieldDecl *Field = Init->getMember();
+  const FieldDecl *Field = Init->getAnyMember();
 
   if (!sameValue(Field->getInClassInitializer(), Init->getInit()))
     return;
Index: test/clang-tidy/modernize-use-default-member-init.cpp
===================================================================
--- test/clang-tidy/modernize-use-default-member-init.cpp
+++ test/clang-tidy/modernize-use-default-member-init.cpp
@@ -382,6 +382,16 @@
   const char *e4 = "bar";
 };
 
+struct UnionExisting {
+  UnionExisting() : e(5.0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: member initializer for 'e' is redundant
+  // CHECK-FIXES: UnionExisting()  {}
+  union {
+    int i;
+    double e = 5.0;
+  };
+};
+
 template <typename T>
 struct NegativeTemplateExisting {
   NegativeTemplateExisting(int) : t(0) {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57665.185141.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190204/bee7b3fd/attachment.bin>


More information about the cfe-commits mailing list