diff --git a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp --- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp +++ b/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; diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-default-member-init.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-default-member-init.cpp --- a/clang-tools-extra/test/clang-tidy/modernize-use-default-member-init.cpp +++ b/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 struct NegativeTemplateExisting { NegativeTemplateExisting(int) : t(0) {}