DC may sometimes be NULL and getContainerInfo(DC, Container) will fail.
See https://github.com/jacobdufault/cquery/issues/192 for the full story.
https://github.com/nlohmann/json/blob/develop/test/src/unit-constructor1.cpp and many other files in that project's test/src/ direcotory cannot be indexed because
https://github.com/llvm-mirror/clang/blob/master/tools/libclang/CXIndexDataConsumer.cpp#L203
c++ handleReference(ND, Loc, Cursor, dyn_cast_or_null<NamedDecl>(ASTNode.Parent), ASTNode.ContainerDC, ASTNode.OrigE, Kind);
dyn_cast_or_null<NamedDecl>(ASTNode.Parent) is somehow a null pointer and in https://github.com/llvm-mirror/clang/blob/master/tools/libclang/CXIndexDataConsumer.cpp#L935
c++ ContainerInfo Container; getContainerInfo(DC, Container);
The null DC is casted ContInfo.cursor = getCursor(cast<Decl>(DC)); and SIGSEGV.
https://github.com/llvm-mirror/clang/blob/master/tools/libclang/CXIndexDataConsumer.cpp#L203
handleReference(ND, Loc, Cursor, dyn_cast_or_null<NamedDecl>(ASTNode.Parent), ASTNode.ContainerDC, ASTNode.OrigE, Kind);
#0 0x00007fa31b51a4b0 in clang::Decl::castFromDeclContext(clang::DeclContext const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #1 0x00007fa31b4a202a in clang::cxindex::CXIndexDataConsumer::handleReference(clang::NamedDecl const*, clang::SourceLocation, CXCursor, clang::NamedDecl const*, clang::DeclContext const*, clang::Expr const*, CXIdxEntityRefKind) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #2 0x00007fa31b4a1871 in clang::cxindex::CXIndexDataConsumer::handleDeclOccurence(clang::Decl const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>, clang::FileID, unsigned int, clang::index::IndexDataConsumer::ASTNodeInfo) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #3 0x00007fa31b77a9a5 in clang::index::IndexingContext::handleDeclOccurrence(clang::Decl const*, clang::SourceLocation, bool, clang::Decl const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>, clang::Expr const*, clang::Decl const*, clang::DeclContext const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #4 0x00007fa31b77acc6 in clang::index::IndexingContext::handleReference(clang::NamedDecl const*, clang::SourceLocation, clang::NamedDecl const*, clang::DeclContext const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>, clang::Expr const*, clang::Decl const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #5 0x00007fa31b7798e0 in (anonymous namespace)::IndexingDeclVisitor::handleTemplateArgumentLoc(clang::TemplateArgumentLoc const&, clang::NamedDecl const*, clang::DeclContext const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #6 0x00007fa31b7797f9 in (anonymous namespace)::IndexingDeclVisitor::VisitTemplateDecl(clang::TemplateDecl const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #7 0x00007fa31b7774d9 in clang::index::IndexingContext::indexDecl(clang::Decl const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #8 0x00007fa31b777709 in clang::declvisitor::Base<clang::declvisitor::make_const_ptr, (anonymous namespace)::IndexingDeclVisitor, bool>::Visit () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #9 0x00007fa31b7774d9 in clang::index::IndexingContext::indexDecl(clang::Decl const*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #10 0x00007fa31b6cf5ba in clang::ASTUnit::visitLocalTopLevelDecls(void*, bool (*)(void*, clang::Decl const*)) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #11 0x00007fa31b77241a in clang::index::indexASTUnit(clang::ASTUnit&, std::shared_ptr<clang::index::IndexDataConsumer>, clang::index::IndexingOptions) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #12 0x00007fa31b4b11ed in clang_indexTranslationUnit::$_1::operator()() const () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #13 0x00007fa31c804980 in llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #14 0x00007fa31c804a34 in RunSafelyOnThread_Dispatch(void*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #15 0x00007fa31c84bcba in ExecuteOnThread_Dispatch(void*) () from /home/maskray/Dev/Util/cquery/build/debug/bin/../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/libclang.so.5 #16 0x00007fa31ecbc494 in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0 #17 0x00007fa31a4d3a8f in clone () from /lib/x86_64-linux-gnu/libc.so.6