[clang-tools-extra] r268369 - Fix a crash in cppcoreguidelines-pro-type-member-init when checking a class that initializes itself as a base
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Tue May 3 01:11:47 PDT 2016
Author: hokein
Date: Tue May 3 03:11:47 2016
New Revision: 268369
URL: http://llvm.org/viewvc/llvm-project?rev=268369&view=rev
Log:
Fix a crash in cppcoreguidelines-pro-type-member-init when checking a class that initializes itself as a base
Summary: Fix a crash when a record type initializes itself in its own base class initializer list.
Patch by Michael Miller!
Reviewers: alexfh, aaron.ballman, hokein
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D19802
Modified:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
Modified: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp?rev=268369&r1=268368&r2=268369&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp Tue May 3 03:11:47 2016
@@ -181,7 +181,7 @@ computeInsertions(const CXXConstructorDe
const auto *InitDecl =
Init->isMemberInitializer()
? static_cast<const NamedDecl *>(Init->getMember())
- : Init->getBaseClass()->getAs<RecordType>()->getDecl();
+ : Init->getBaseClass()->getAsCXXRecordDecl();
// Add all fields between current field up until the next intializer.
for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
@@ -401,7 +401,7 @@ void ProTypeMemberInitCheck::checkMissin
// Remove any bases that were explicitly written in the initializer list.
for (const CXXCtorInitializer *Init : Ctor->inits()) {
if (Init->isBaseInitializer() && Init->isWritten())
- BasesToInit.erase(Init->getBaseClass()->getAs<RecordType>()->getDecl());
+ BasesToInit.erase(Init->getBaseClass()->getAsCXXRecordDecl());
}
if (BasesToInit.empty())
Modified: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp?rev=268369&r1=268368&r2=268369&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp Tue May 3 03:11:47 2016
@@ -346,3 +346,14 @@ struct NegativeDeletedConstructor : Nega
Template<int> F;
};
+
+// This pathological template fails to compile if actually instantiated. It
+// results in the check seeing a null RecordDecl when examining the base class
+// initializer list.
+template <typename T>
+class PositiveSelfInitialization : NegativeAggregateType
+{
+ PositiveSelfInitialization() : PositiveSelfInitialization() {}
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor does not initialize these bases: NegativeAggregateType
+ // CHECK-FIXES: PositiveSelfInitialization() : NegativeAggregateType(), PositiveSelfInitialization() {}
+};
More information about the cfe-commits
mailing list