[PATCH] D19802: Fix a crash in cppcoreguidelines-pro-type-member-init when checking a class that initializes itself as a base
Michael Miller via cfe-commits
cfe-commits at lists.llvm.org
Mon May 2 04:59:35 PDT 2016
michael_miller created this revision.
michael_miller added reviewers: hokein, alexfh, aaron.ballman.
michael_miller added a subscriber: cfe-commits.
Fix a crash when a record type initializes itself in its own base class initializer list.
http://reviews.llvm.org/D19802
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
@@ -338,3 +338,11 @@
Template<int> F;
};
+
+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() {}
+};
Index: clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -179,7 +179,7 @@
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) {
@@ -398,7 +398,7 @@
// 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())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19802.55805.patch
Type: text/x-patch
Size: 1776 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160502/3da4b2de/attachment.bin>
More information about the cfe-commits
mailing list