[clang] 85208b9 - [clang][deps] NFC: Stop using moved-from object

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 14 06:16:17 PDT 2021


Author: Jan Svoboda
Date: 2021-06-14T15:16:08+02:00
New Revision: 85208b96b85f6f3e502cf4b7fd5f440434d1c7e5

URL: https://github.com/llvm/llvm-project/commit/85208b96b85f6f3e502cf4b7fd5f440434d1c7e5
DIFF: https://github.com/llvm/llvm-project/commit/85208b96b85f6f3e502cf4b7fd5f440434d1c7e5.diff

LOG: [clang][deps] NFC: Stop using moved-from object

The dependency scanning worker uses `std::move` to "reset" `DependencyOutputOptions` in the `CompilerInstance` that performs the implicit build. It's probably preferable to replace the object with value-initialized instance, rather than depending on the behavior of a moved-from object.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D104106

Added: 
    

Modified: 
    clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 48abc095231f..cd3463aa13e6 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -171,8 +171,8 @@ class DependencyScanningAction : public tooling::ToolAction {
     // invocation to the collector. The options in the invocation are reset,
     // which ensures that the compiler won't create new dependency collectors,
     // and thus won't write out the extra '.d' files to disk.
-    auto Opts = std::make_unique<DependencyOutputOptions>(
-        std::move(Compiler.getInvocation().getDependencyOutputOpts()));
+    auto Opts = std::make_unique<DependencyOutputOptions>();
+    std::swap(*Opts, Compiler.getInvocation().getDependencyOutputOpts());
     // We need at least one -MT equivalent for the generator of make dependency
     // files to work.
     if (Opts->Targets.empty())


        


More information about the cfe-commits mailing list