[clang] [Clang][NFC] Use std::move to avoid copy (PR #138073)

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 30 18:50:09 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

<details>
<summary>Changes</summary>

Static analysis flagged this code for using copy when we could use std::move.

Worth noting that CD.Message is a StringRef but Conflict.Message is std::string. Otherwise I would have used a temporary in place and avoid a local variable.

---
Full diff: https://github.com/llvm/llvm-project/pull/138073.diff


1 Files Affected:

- (modified) clang/lib/Lex/ModuleMap.cpp (+2-1) 


``````````diff
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index a1394fd3900b0..0b47ff5fa71f8 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -2010,7 +2010,8 @@ void ModuleMapLoader::handleConflict(const modulemap::ConflictDecl &CD) {
   Conflict.Id = CD.Id;
   Conflict.Message = CD.Message;
 
-  ActiveModule->UnresolvedConflicts.push_back(Conflict);
+  // FIXME: when we move to C++20 we should consider using emplace_back
+  ActiveModule->UnresolvedConflicts.push_back(std::move(Conflict));
 }
 
 void ModuleMapLoader::handleInferredModuleDecl(

``````````

</details>


https://github.com/llvm/llvm-project/pull/138073


More information about the cfe-commits mailing list