[clangd] Use function pointer instead of function_ref to avoid GCC 5 bug

With GCC <6 constructing a function_ref from a free function reference
leads to it referencing a temporary function pointer. If the lifetime of
that temporary is insufficient it can crash.

Fixes https://github.com/clangd/clangd/issues/800
This commit is contained in:
Sam McCall 2021-07-27 13:52:32 +02:00
parent 76f3ffb2b2
commit ec1fb95333
1 changed files with 2 additions and 3 deletions

View File

@ -279,11 +279,10 @@ bool DirectoryBasedGlobalCompilationDatabase::DirectoryCache::load(
struct CDBFile {
CachedFile *File;
// Wrapper for {Fixed,JSON}CompilationDatabase::loadFromBuffer.
llvm::function_ref<std::unique_ptr<tooling::CompilationDatabase>(
std::unique_ptr<tooling::CompilationDatabase> (*Parser)(
PathRef,
/*Data*/ llvm::StringRef,
/*ErrorMsg*/ std::string &)>
Parser;
/*ErrorMsg*/ std::string &);
};
for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
CDBFile{&BuildCompileCommandsJson, parseJSON},