Summary:
clang-tidy's modernize-use-default-member-init was crashing for unions
with an existing default member initializer.
Fixes PR40492
Reviewers: aaron.ballman, alexfh, JonasToth
Reviewed By: JonasToth
Subscribers: JonasToth, riccibruno, xazax.hun, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D57665
llvm-svn: 353092
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;
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) {}