From 20d4c20bca22b82f907166b40abc2f4139a3eee4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 27 Apr 2016 12:17:04 +0000 Subject: Fix a crash in cppcoreguidelines-pro-type-member-init when checking a type with a template parameter as a base class. Summary: Fixed a crash in cppcoreguidelines-pro-type-member-init when encountering a type that uses one of its template parameters as a base when compiling for C++98. Patch by Michael Miller! Reviewers: aaron.ballman, alexfh, hokein Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19539 llvm-svn: 267700 --- .../clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines') diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index 7aba5242962..d41175e27d2 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -208,8 +208,12 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits, void getInitializationsInOrder(const CXXRecordDecl *ClassDecl, SmallVectorImpl &Decls) { Decls.clear(); - for (const auto &Base : ClassDecl->bases()) - Decls.emplace_back(getCanonicalRecordDecl(Base.getType())); + for (const auto &Base : ClassDecl->bases()) { + // Decl may be null if the base class is a template parameter. + if (const NamedDecl *Decl = getCanonicalRecordDecl(Base.getType())) { + Decls.emplace_back(Decl); + } + } Decls.append(ClassDecl->fields().begin(), ClassDecl->fields().end()); } -- cgit v1.2.3