From f59b600c21add076d6a876f29f94990b24b8e321 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat Date: Thu, 5 Dec 2024 07:16:51 -0800 Subject: [PATCH] [NFC] Complete proper copying and resource cleanup in classes. (#118655) Provide, where missing, a copy constructor, a copy assignment operator or a destructor to prevent potential issues that can arise. --- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h | 3 +++ clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h | 2 ++ clang-tools-extra/clangd/ClangdLSPServer.h | 3 +++ clang-tools-extra/clangd/ParsedAST.h | 3 +++ clang-tools-extra/clangd/TUScheduler.cpp | 6 +++++- clang-tools-extra/clangd/TUScheduler.h | 3 +++ clang-tools-extra/clangd/support/DirectiveTree.cpp | 3 +++ clang-tools-extra/modularize/ModuleAssistant.cpp | 2 ++ 8 files changed, 24 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h index 97e16a12febd..ff42f96a0477 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -81,6 +81,9 @@ public: ~ClangTidyContext(); + ClangTidyContext(const ClangTidyContext &) = delete; + ClangTidyContext &operator=(const ClangTidyContext &) = delete; + /// Report any errors detected using this method. /// /// This is still under heavy development and will likely change towards using diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h index e862195abaab..f66285672d04 100644 --- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h +++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h @@ -31,6 +31,8 @@ class NoLintDirectiveHandler { public: NoLintDirectiveHandler(); ~NoLintDirectiveHandler(); + NoLintDirectiveHandler(const NoLintDirectiveHandler &) = delete; + NoLintDirectiveHandler &operator=(const NoLintDirectiveHandler &) = delete; bool shouldSuppress(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Diag, llvm::StringRef DiagName, diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 597fd9de7ff6..f43734ec1ede 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -73,6 +73,9 @@ public: /// The destructor blocks on any outstanding background tasks. ~ClangdLSPServer(); + ClangdLSPServer(const ClangdLSPServer &other) = delete; + ClangdLSPServer &operator=(const ClangdLSPServer &other) = delete; + /// Run LSP server loop, communicating with the Transport provided in the /// constructor. This method must not be executed more than once. /// diff --git a/clang-tools-extra/clangd/ParsedAST.h b/clang-tools-extra/clangd/ParsedAST.h index 63e564bd68a7..8d9d1e645692 100644 --- a/clang-tools-extra/clangd/ParsedAST.h +++ b/clang-tools-extra/clangd/ParsedAST.h @@ -59,6 +59,9 @@ public: ~ParsedAST(); + ParsedAST(const ParsedAST &Other) = delete; + ParsedAST &operator=(const ParsedAST &Other) = delete; + /// Note that the returned ast will not contain decls from the preamble that /// were not deserialized during parsing. Clients should expect only decls /// from the main file to be in the AST. diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index 71548b59cc30..035e5e63d8fb 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -411,6 +411,9 @@ public: if (Throttler) Throttler->release(ID); } + PreambleThrottlerRequest(const PreambleThrottlerRequest &) = delete; + PreambleThrottlerRequest & + operator=(const PreambleThrottlerRequest &) = delete; private: PreambleThrottler::RequestID ID; @@ -621,7 +624,8 @@ public: AsyncTaskRunner *Tasks, Semaphore &Barrier, const TUScheduler::Options &Opts, ParsingCallbacks &Callbacks); ~ASTWorker(); - + ASTWorker(const ASTWorker &other) = delete; + ASTWorker &operator=(const ASTWorker &other) = delete; void update(ParseInputs Inputs, WantDiagnostics, bool ContentChanged); void runWithAST(llvm::StringRef Name, diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h index fb936d46bbcf..d0da20310a8b 100644 --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -242,6 +242,9 @@ public: std::unique_ptr ASTCallbacks = nullptr); ~TUScheduler(); + TUScheduler(const TUScheduler &other) = delete; + TUScheduler &operator=(const TUScheduler &other) = delete; + struct FileStats { std::size_t UsedBytesAST = 0; std::size_t UsedBytesPreamble = 0; diff --git a/clang-tools-extra/clangd/support/DirectiveTree.cpp b/clang-tools-extra/clangd/support/DirectiveTree.cpp index d25da111681a..7ea08add7a10 100644 --- a/clang-tools-extra/clangd/support/DirectiveTree.cpp +++ b/clang-tools-extra/clangd/support/DirectiveTree.cpp @@ -328,6 +328,9 @@ public: Preprocessor(const TokenStream &In, TokenStream &Out) : In(In), Out(Out) {} ~Preprocessor() { Out.finalize(); } + Preprocessor(const Preprocessor &other) = delete; + Preprocessor &operator=(const Preprocessor &other) = delete; + void walk(const DirectiveTree &T) { for (const auto &C : T.Chunks) std::visit(*this, C); diff --git a/clang-tools-extra/modularize/ModuleAssistant.cpp b/clang-tools-extra/modularize/ModuleAssistant.cpp index 5c11ffdb8589..c7259d70bd58 100644 --- a/clang-tools-extra/modularize/ModuleAssistant.cpp +++ b/clang-tools-extra/modularize/ModuleAssistant.cpp @@ -46,6 +46,8 @@ class Module { public: Module(llvm::StringRef Name, bool Problem); ~Module(); + Module(const Module &other) = delete; + Module &operator=(const Module &other) = delete; bool output(llvm::raw_fd_ostream &OS, int Indent); Module *findSubModule(llvm::StringRef SubName);