[llvm] [Support] Simplify setDefaultImpl (NFC) (PR #137528)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 12:55:14 PDT 2025
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/137528
>From ea2d0bec1f8a2ea05e22b3227d6e28672a24d966 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 27 Apr 2025 09:08:44 -0700
Subject: [PATCH 1/2] [Support] Simplify setDefaultImpl (NFC)
We can use "constexpr if" to combine the two variants of functions.
---
llvm/include/llvm/Support/CommandLine.h | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
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() {
>From 3d437a2530821d2fc79573faf2e2453469304f62 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 27 Apr 2025 12:47:22 -0700
Subject: [PATCH 2/2] Address a comment.
---
llvm/include/llvm/Support/CommandLine.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 4c9f5bae87759..531750572102c 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1459,18 +1459,16 @@ class opt
}
}
- template <class T> void setDefaultImpl() {
- if constexpr (std::is_assignable_v<T &, T>) {
+ void setDefault() override {
+ if constexpr (std::is_assignable_v<DataType &, DataType>) {
const OptionValue<DataType> &V = this->getDefault();
if (V.hasValue())
this->setValue(V.getValue());
else
- this->setValue(T());
+ this->setValue(DataType());
}
}
- void setDefault() override { setDefaultImpl<DataType>(); }
-
void done() {
addArgument();
Parser.initialize();
More information about the llvm-commits
mailing list