[clang-tools-extra] r353092 - [clang-tidy] Handle unions with existing default-member-init
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 4 13:09:31 PST 2019
Author: malcolm.parsons
Date: Mon Feb 4 13:09:31 2019
New Revision: 353092
URL: http://llvm.org/viewvc/llvm-project?rev=353092&view=rev
Log:
[clang-tidy] Handle unions with existing default-member-init
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
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=353092&r1=353091&r2=353092&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp Mon Feb 4 13:09:31 2019
@@ -273,7 +273,7 @@ void UseDefaultMemberInitCheck::checkDef
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;
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp?rev=353092&r1=353091&r2=353092&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-default-member-init.cpp Mon Feb 4 13:09:31 2019
@@ -382,6 +382,16 @@ struct ExistingString {
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) {}
More information about the cfe-commits
mailing list