[PATCH] D19802: 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:17:49 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268369: Fix a crash in cppcoreguidelines-pro-type-member-init when checking a class… (authored by hokein).
Changed prior to commit:
http://reviews.llvm.org/D19802?vs=55904&id=55956#toc
Repository:
rL LLVM
http://reviews.llvm.org/D19802
Files:
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -181,7 +181,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) {
@@ -401,7 +401,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())
Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
@@ -346,3 +346,14 @@
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() {}
+};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19802.55956.patch
Type: text/x-patch
Size: 2099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160503/d160bffc/attachment-0001.bin>
More information about the cfe-commits
mailing list