[llvm] [Support] Simplify setDefaultImpl (NFC) (PR #137528)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 10:01:10 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

We can use "constexpr if" to combine the two variants of functions.


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


1 Files Affected:

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


``````````diff
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 5d60bb64bbb20..4c9f5bae87759 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1459,18 +1459,16 @@ class opt
     }
   }
 
-  template <class T, class = std::enable_if_t<std::is_assignable_v<T &, T>>>
-  void setDefaultImpl() {
-    const OptionValue<DataType> &V = this->getDefault();
-    if (V.hasValue())
-      this->setValue(V.getValue());
-    else
-      this->setValue(T());
+  template <class T> void setDefaultImpl() {
+    if constexpr (std::is_assignable_v<T &, T>) {
+      const OptionValue<DataType> &V = this->getDefault();
+      if (V.hasValue())
+        this->setValue(V.getValue());
+      else
+        this->setValue(T());
+    }
   }
 
-  template <class T, class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
-  void setDefaultImpl(...) {}
-
   void setDefault() override { setDefaultImpl<DataType>(); }
 
   void done() {

``````````

</details>


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


More information about the llvm-commits mailing list