diff options
| -rw-r--r-- | clang-tools-extra/clangd/GlobalCompilationDatabase.cpp | 6 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp index b40ae26cd3e..9a09482ce39 100644 --- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -58,9 +58,11 @@ static std::string getFallbackClangPath() { tooling::CompileCommand GlobalCompilationDatabase::getFallbackCommand(PathRef File) const { std::vector<std::string> 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 index 6761deb70ac..6823fc557ee 100644 --- a/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp +++ b/clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp @@ -36,6 +36,10 @@ TEST(GlobalCompilationDatabaseTest, FallbackCommand) { 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) { |

