[llvm] Add an llvm::cl::opt::operator=(T &&Val) (PR #147502)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 03:46:16 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Tom Natan (tomnatan30)

<details>
<summary>Changes</summary>

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).

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


1 Files Affected:

- (modified) llvm/include/llvm/Support/CommandLine.h (+6) 


``````````diff
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) {

``````````

</details>


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


More information about the llvm-commits mailing list