diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp --- a/clang-tools-extra/clangd/Preamble.cpp +++ b/clang-tools-extra/clangd/Preamble.cpp @@ -229,9 +229,8 @@ llvm::Expected scanPreamble(llvm::StringRef Contents, const tooling::CompileCommand &Cmd) { class EmptyFS : public ThreadsafeFS { - public: - llvm::IntrusiveRefCntPtr - view(llvm::NoneType) const override { + private: + llvm::IntrusiveRefCntPtr viewImpl() const override { return new llvm::vfs::InMemoryFileSystem; } }; diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.h b/clang-tools-extra/clangd/support/ThreadsafeFS.h --- a/clang-tools-extra/clangd/support/ThreadsafeFS.h +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.h @@ -30,20 +30,25 @@ virtual ~ThreadsafeFS() = default; /// Obtain a vfs::FileSystem with an arbitrary initial working directory. - virtual llvm::IntrusiveRefCntPtr - view(llvm::NoneType CWD) const = 0; + llvm::IntrusiveRefCntPtr + view(llvm::NoneType CWD) const { + return viewImpl(); + } /// Obtain a vfs::FileSystem with a specified working directory. /// If the working directory can't be set (e.g. doesn't exist), logs and /// returns the FS anyway. - virtual llvm::IntrusiveRefCntPtr - view(PathRef CWD) const; + llvm::IntrusiveRefCntPtr view(PathRef CWD) const; + +private: + /// Overridden by implementations to provide a vfs::FileSystem. + /// This is distinct from view(NoneType) to avoid GCC's -Woverloaded-virtual. + virtual llvm::IntrusiveRefCntPtr viewImpl() const = 0; }; class RealThreadsafeFS : public ThreadsafeFS { -public: - llvm::IntrusiveRefCntPtr - view(llvm::NoneType) const override; +private: + llvm::IntrusiveRefCntPtr viewImpl() const override; }; } // namespace clangd diff --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp --- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp +++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp @@ -83,7 +83,7 @@ } llvm::IntrusiveRefCntPtr -RealThreadsafeFS::view(llvm::NoneType) const { +RealThreadsafeFS::viewImpl() const { // Avoid using memory-mapped files. // FIXME: Try to use a similar approach in Sema instead of relying on // propagation of the 'isVolatile' flag through all layers. diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -273,12 +273,13 @@ TEST_F(ClangdVFSTest, PropagatesContexts) { static Key Secret; struct ContextReadingFS : public ThreadsafeFS { - IntrusiveRefCntPtr - view(llvm::NoneType) const override { + mutable int Got; + + private: + IntrusiveRefCntPtr viewImpl() const override { Got = Context::current().getExisting(Secret); return buildTestFS({}); } - mutable int Got; } FS; struct Callbacks : public ClangdServer::Callbacks { void onDiagnosticsReady(PathRef File, llvm::StringRef Version, @@ -925,12 +926,17 @@ // preamble again. (They should be using the preamble's stat-cache) TEST(ClangdTests, PreambleVFSStatCache) { class StatRecordingFS : public ThreadsafeFS { + llvm::StringMap &CountStats; + public: + // If relative paths are used, they are resolved with testPath(). + llvm::StringMap Files; + StatRecordingFS(llvm::StringMap &CountStats) : CountStats(CountStats) {} - IntrusiveRefCntPtr - view(llvm::NoneType) const override { + private: + IntrusiveRefCntPtr viewImpl() const override { class StatRecordingVFS : public llvm::vfs::ProxyFileSystem { public: StatRecordingVFS(IntrusiveRefCntPtr FS, @@ -954,10 +960,6 @@ return IntrusiveRefCntPtr( new StatRecordingVFS(buildTestFS(Files), CountStats)); } - - // If relative paths are used, they are resolved with testPath(). - llvm::StringMap Files; - llvm::StringMap &CountStats; }; llvm::StringMap CountStats; diff --git a/clang-tools-extra/clangd/unittests/TestFS.h b/clang-tools-extra/clangd/unittests/TestFS.h --- a/clang-tools-extra/clangd/unittests/TestFS.h +++ b/clang-tools-extra/clangd/unittests/TestFS.h @@ -33,8 +33,7 @@ // A VFS provider that returns TestFSes containing a provided set of files. class MockFS : public ThreadsafeFS { public: - IntrusiveRefCntPtr - view(llvm::NoneType) const override { + IntrusiveRefCntPtr viewImpl() const override { return buildTestFS(Files, Timestamps); }