[llvm] Add an llvm::cl::opt::operator=(T &&Val) (PR #147502)
Tom Natan via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 03:45:44 PDT 2025
https://github.com/tomnatan30 created https://github.com/llvm/llvm-project/pull/147502
Add an llvm::cl::opt::operator= that takes an rvalue reference of value, to avoid an unecessary copy for types with memory allocation (string, vector, etc).
>From ff3b71edde5dd9550215607f0cb040f5eb62773c Mon Sep 17 00:00:00 2001
From: tomnatan30 <tomnatan at google.com>
Date: Tue, 8 Jul 2025 10:43:48 +0000
Subject: [PATCH] Add an llvm::cl::opt::operator= that takes an rvalue
reference of the value, to avoid an unecessary copy for types with memory
allocation (string, vector, etc)
---
llvm/include/llvm/Support/CommandLine.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 5489b3ff78f51..adaa75cc6c348 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1496,6 +1496,12 @@ class opt
return this->getValue();
}
+ template <class T> DataType &operator=(T &&Val) {
+ this->getValue() = std::forward<T>(Val);
+ Callback(this->getValue());
+ return this->getValue();
+ }
+
template <class... Mods>
explicit opt(const Mods &... Ms)
: Option(llvm::cl::Optional, NotHidden), Parser(*this) {
More information about the llvm-commits
mailing list