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

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 30 18:49:35 PDT 2025


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

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.

>From 85cb5224fa791947740a97c8e9b983323afa5608 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Wed, 30 Apr 2025 18:44:48 -0700
Subject: [PATCH] [Clang][NFC] Use std::move to avoid copy

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.
---
 clang/lib/Lex/ModuleMap.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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(



More information about the cfe-commits mailing list