[PATCH] D57665: [clang-tidy] Handle unions with existing default-member-init
Malcolm Parsons via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 3 13:47:46 PST 2019
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, alexfh.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
clang-tidy's modernize-use-default-member-init was crashing for unions
with an existing default member initializer.
Fixes PR40492
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D57665
Files:
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/test/clang-tidy/modernize-use-default-member-init.cpp
Index: clang-tools-extra/test/clang-tidy/modernize-use-default-member-init.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/modernize-use-default-member-init.cpp
+++ clang-tools-extra/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) {}
Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57665.184976.patch
Type: text/x-patch
Size: 1315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190203/de11f73e/attachment-0001.bin>
More information about the cfe-commits
mailing list