diff options
author | Haojian Wu <hokein@google.com> | 2016-04-20 08:29:08 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2016-04-20 08:29:08 +0000 |
commit | 257914e7c9d1e1ccf46e680616a1c2d5b31953c3 (patch) | |
tree | da40e94e5b67c2c606c8beaefae2b0fff3c82e1e | |
parent | 117625aaf3d2c831a8e490820637e7a7e9b59696 (diff) | |
download | bcm5719-llvm-257914e7c9d1e1ccf46e680616a1c2d5b31953c3.tar.gz bcm5719-llvm-257914e7c9d1e1ccf46e680616a1c2d5b31953c3.zip |
Fix a crash in cppcoreguidelines-pro-type-member-init related to missing constructor bodies.
Summary: 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.
Patch by Michael Miller!
Reviewers: aaron.ballman, alexfh, hokein
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D19270
llvm-svn: 266862
-rw-r--r-- | clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp | 10 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp | 7 |
2 files changed, 11 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index e5093540c1b..90391680ac1 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -285,6 +285,9 @@ void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) { 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 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer( 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 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer( 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. diff --git a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp index a4140eb68a6..8f9c0e3f6a5 100644 --- a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp +++ b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp @@ -331,3 +331,10 @@ struct PositiveAnonymousUnionAndStruct { int X; // CHECK-FIXES: int X{}; }; + +// This check results in a CXXConstructorDecl with no body. +struct NegativeDeletedConstructor : NegativeAggregateType { + NegativeDeletedConstructor() = delete; + + Template<int> F; +}; |