[PATCH] D19270: Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.
Michael Miller via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 19 09:31:51 PDT 2016
michael_miller created this revision.
michael_miller added reviewers: alexfh, aaron.ballman, hokein.
michael_miller added a subscriber: cfe-commits.
Fixes a crash in cppcoreguidelines-pro-type-member-init when checking some record types with a constructor without a body. We now check to make sure the constructor has a body before looking for missing members and base initializers.
http://reviews.llvm.org/D19270
Files:
clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
Index: test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===================================================================
--- test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -331,3 +331,10 @@
int X;
// CHECK-FIXES: int X{};
};
+
+// This check results in a CXXConstructorDecl with no body.
+struct NegativeDeletedConstructor : NegativeAggregateType {
+ NegativeDeletedConstructor() = delete;
+
+ Template<int> F;
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -285,6 +285,9 @@
void ProTypeMemberInitCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor")) {
+ // Skip declarations delayed by late template parsing without a body.
+ if (!Ctor->getBody())
+ return;
checkMissingMemberInitializer(*Result.Context, Ctor);
checkMissingBaseClassInitializer(*Result.Context, Ctor);
} else if (const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var")) {
@@ -304,11 +307,6 @@
if (IsUnion && ClassDecl->hasInClassInitializer())
return;
- // Skip declarations delayed by late template parsing without a body.
- const Stmt *Body = Ctor->getBody();
- if (!Body)
- return;
-
SmallPtrSet<const FieldDecl *, 16> FieldsToInit;
fieldsRequiringInit(ClassDecl->fields(), Context, FieldsToInit);
if (FieldsToInit.empty())
@@ -323,7 +321,7 @@
FieldsToInit.erase(Init->getMember());
}
}
- removeFieldsInitializedInBody(*Body, Context, FieldsToInit);
+ removeFieldsInitializedInBody(*Ctor->getBody(), Context, FieldsToInit);
// Collect all fields in order, both direct fields and indirect fields from
// anonmyous record types.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19270.54210.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160419/458684a5/attachment.bin>
More information about the cfe-commits
mailing list