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 @@ -230,8 +230,7 @@ scanPreamble(llvm::StringRef Contents, const tooling::CompileCommand &Cmd) { class EmptyFS : public ThreadsafeFS { public: - llvm::IntrusiveRefCntPtr - view(llvm::NoneType) const override { + 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; + 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,8 +273,7 @@ TEST_F(ClangdVFSTest, PropagatesContexts) { static Key Secret; struct ContextReadingFS : public ThreadsafeFS { - IntrusiveRefCntPtr - view(llvm::NoneType) const override { + IntrusiveRefCntPtr viewImpl() const override { Got = Context::current().getExisting(Secret); return buildTestFS({}); } @@ -929,8 +928,7 @@ StatRecordingFS(llvm::StringMap &CountStats) : CountStats(CountStats) {} - IntrusiveRefCntPtr - view(llvm::NoneType) const override { + IntrusiveRefCntPtr viewImpl() const override { class StatRecordingVFS : public llvm::vfs::ProxyFileSystem { public: StatRecordingVFS(IntrusiveRefCntPtr FS, 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); }