Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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

We can use "constexpr if" to combine the two variants of functions.
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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() {

@kazutakahirata kazutakahirata merged commit 4ca8f65 into llvm:main Apr 27, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_constexpr_if_llvm_CommandLine branch April 27, 2025 21:13
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
We can use "constexpr if" to combine the two variants of functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants