diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp --- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -58,9 +58,11 @@ tooling::CompileCommand GlobalCompilationDatabase::getFallbackCommand(PathRef File) const { std::vector Argv = {getFallbackClangPath()}; - // Clang treats .h files as C by default, resulting in unhelpful diagnostics. + // Clang treats .h files as C by default and files without extension as linker + // input, resulting in unhelpful diagnostics. // Parsing as Objective C++ is friendly to more cases. - if (llvm::sys::path::extension(File) == ".h") + auto FileExtension = llvm::sys::path::extension(File); + if (FileExtension.empty() || FileExtension == ".h") Argv.push_back("-xobjective-c++-header"); Argv.push_back(File); tooling::CompileCommand Cmd(llvm::sys::path::parent_path(File), diff --git a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp --- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp @@ -36,6 +36,10 @@ EXPECT_THAT(Cmd.CommandLine, ElementsAre(EndsWith("clang"), "-xobjective-c++-header", testPath("foo/bar.h"))); + Cmd = DB.getFallbackCommand(testPath("foo/bar")); + EXPECT_THAT(Cmd.CommandLine, + ElementsAre(EndsWith("clang"), "-xobjective-c++-header", + testPath("foo/bar"))); } static tooling::CompileCommand cmd(llvm::StringRef File, llvm::StringRef Arg) {