diff options
-rw-r--r-- | clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp | 5 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/fuchsia-multiple-inheritance.cpp | 11 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp index d4624d013f4..35504c98278 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp @@ -30,6 +30,7 @@ AST_MATCHER(CXXRecordDecl, hasBases) { // previously. void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node, bool isInterface) { + assert(Node->getIdentifier()); StringRef Name = Node->getIdentifier()->getName(); InterfaceMap.insert(std::make_pair(Name, isInterface)); } @@ -39,6 +40,7 @@ void MultipleInheritanceCheck::addNodeToInterfaceMap(const CXXRecordDecl *Node, // interface status for the current node is not yet known. bool MultipleInheritanceCheck::getInterfaceStatus(const CXXRecordDecl *Node, bool &isInterface) const { + assert(Node->getIdentifier()); StringRef Name = Node->getIdentifier()->getName(); llvm::StringMapConstIterator<bool> Pair = InterfaceMap.find(Name); if (Pair == InterfaceMap.end()) @@ -59,6 +61,9 @@ bool MultipleInheritanceCheck::isCurrentClassInterface( } bool MultipleInheritanceCheck::isInterface(const CXXRecordDecl *Node) { + if (!Node->getIdentifier()) + return false; + // Short circuit the lookup if we have analyzed this record before. bool PreviousIsInterfaceResult; if (getInterfaceStatus(Node, PreviousIsInterfaceResult)) diff --git a/clang-tools-extra/test/clang-tidy/fuchsia-multiple-inheritance.cpp b/clang-tools-extra/test/clang-tidy/fuchsia-multiple-inheritance.cpp index e61e1299bac..fd2ed145c12 100644 --- a/clang-tools-extra/test/clang-tidy/fuchsia-multiple-inheritance.cpp +++ b/clang-tools-extra/test/clang-tidy/fuchsia-multiple-inheritance.cpp @@ -134,3 +134,14 @@ template<typename T> struct B : virtual T {}; template<typename> struct C {}; template<typename T> struct D : C<T> {}; + +// Check clang_tidy does not crash on this code. +template <class T> +struct WithTemplBase : T { + WithTemplBase(); +}; + +int test_no_crash() { + auto foo = []() {}; + WithTemplBase<decltype(foo)>(); +} |