[clangd] Avoid null result in FindRecordTypeAt()
[platform/upstream/llvm.git] / clang-tools-extra / clangd / XRefs.cpp
index da1a803..f81e022 100644 (file)
@@ -1857,7 +1857,8 @@ std::vector<const CXXRecordDecl *> findRecordTypeAt(ParsedAST &AST,
 
       if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
         // If this is a variable, use the type of the variable.
-        Records.push_back(VD->getType().getTypePtr()->getAsCXXRecordDecl());
+        if (const auto *RD = VD->getType().getTypePtr()->getAsCXXRecordDecl())
+          Records.push_back(RD);
         continue;
       }